blob: 0125914e57a8f6963f72d666b1c21d02a9ae9e32 [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
46std::string SsrcToString(uint32_t ssrc) {
47 std::stringstream ss;
48 ss << "SSRC " << ssrc;
49 return ss.str();
50}
51
52// Checks whether an SSRC is contained in the list of desired SSRCs.
53// Note that an empty SSRC list matches every SSRC.
54bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
55 if (desired_ssrc.size() == 0)
56 return true;
57 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
58 desired_ssrc.end();
59}
60
61double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
62 // The timestamp is a fixed point representation with 6 bits for seconds
63 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
64 // time in seconds and then multiply by 1000000 to convert to microseconds.
65 static constexpr double kTimestampToMicroSec =
tereliusccbbf8d2016-08-10 07:34:28 -070066 1000000.0 / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -070067 return abs_send_time * kTimestampToMicroSec;
68}
69
70// Computes the difference |later| - |earlier| where |later| and |earlier|
71// are counters that wrap at |modulus|. The difference is chosen to have the
72// least absolute value. For example if |modulus| is 8, then the difference will
73// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
74// be in [-4, 4].
75int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
76 RTC_DCHECK_LE(1, modulus);
77 RTC_DCHECK_LT(later, modulus);
78 RTC_DCHECK_LT(earlier, modulus);
79 int64_t difference =
80 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
81 int64_t max_difference = modulus / 2;
82 int64_t min_difference = max_difference - modulus + 1;
83 if (difference > max_difference) {
84 difference -= modulus;
85 }
86 if (difference < min_difference) {
87 difference += modulus;
88 }
terelius6addf492016-08-23 17:34:07 -070089 if (difference > max_difference / 2 || difference < min_difference / 2) {
90 LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
91 << " expected to be in the range (" << min_difference / 2
92 << "," << max_difference / 2 << ") but is " << difference
93 << ". Correct unwrapping is uncertain.";
94 }
terelius54ce6802016-07-13 06:44:41 -070095 return difference;
96}
97
ivocaac9d6f2016-09-22 07:01:47 -070098// Return default values for header extensions, to use on streams without stored
99// mapping data. Currently this only applies to audio streams, since the mapping
100// is not stored in the event log.
101// TODO(ivoc): Remove this once this mapping is stored in the event log for
102// audio streams. Tracking bug: webrtc:6399
103webrtc::RtpHeaderExtensionMap GetDefaultHeaderExtensionMap() {
104 webrtc::RtpHeaderExtensionMap default_map;
danilchap4aecc582016-11-15 09:21:00 -0800105 default_map.Register<AudioLevel>(webrtc::RtpExtension::kAudioLevelDefaultId);
106 default_map.Register<AbsoluteSendTime>(
ivocaac9d6f2016-09-22 07:01:47 -0700107 webrtc::RtpExtension::kAbsSendTimeDefaultId);
108 return default_map;
109}
110
tereliusdc35dcd2016-08-01 12:03:27 -0700111constexpr float kLeftMargin = 0.01f;
112constexpr float kRightMargin = 0.02f;
113constexpr float kBottomMargin = 0.02f;
114constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700115
terelius6addf492016-08-23 17:34:07 -0700116class PacketSizeBytes {
117 public:
118 using DataType = LoggedRtpPacket;
119 using ResultType = size_t;
120 size_t operator()(const LoggedRtpPacket& packet) {
121 return packet.total_length;
122 }
123};
124
125class SequenceNumberDiff {
126 public:
127 using DataType = LoggedRtpPacket;
128 using ResultType = int64_t;
129 int64_t operator()(const LoggedRtpPacket& old_packet,
130 const LoggedRtpPacket& new_packet) {
131 return WrappingDifference(new_packet.header.sequenceNumber,
132 old_packet.header.sequenceNumber, 1ul << 16);
133 }
134};
135
tereliusccbbf8d2016-08-10 07:34:28 -0700136class NetworkDelayDiff {
137 public:
138 class AbsSendTime {
139 public:
140 using DataType = LoggedRtpPacket;
141 using ResultType = double;
142 double operator()(const LoggedRtpPacket& old_packet,
143 const LoggedRtpPacket& new_packet) {
144 if (old_packet.header.extension.hasAbsoluteSendTime &&
145 new_packet.header.extension.hasAbsoluteSendTime) {
146 int64_t send_time_diff = WrappingDifference(
147 new_packet.header.extension.absoluteSendTime,
148 old_packet.header.extension.absoluteSendTime, 1ul << 24);
149 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
150 return static_cast<double>(recv_time_diff -
151 AbsSendTimeToMicroseconds(send_time_diff)) /
152 1000;
153 } else {
154 return 0;
155 }
156 }
157 };
158
159 class CaptureTime {
160 public:
161 using DataType = LoggedRtpPacket;
162 using ResultType = double;
163 double operator()(const LoggedRtpPacket& old_packet,
164 const LoggedRtpPacket& new_packet) {
165 int64_t send_time_diff = WrappingDifference(
166 new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32);
167 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
168
169 const double kVideoSampleRate = 90000;
170 // TODO(terelius): We treat all streams as video for now, even though
171 // audio might be sampled at e.g. 16kHz, because it is really difficult to
172 // figure out the true sampling rate of a stream. The effect is that the
173 // delay will be scaled incorrectly for non-video streams.
174
175 double delay_change =
176 static_cast<double>(recv_time_diff) / 1000 -
177 static_cast<double>(send_time_diff) / kVideoSampleRate * 1000;
terelius6addf492016-08-23 17:34:07 -0700178 if (delay_change < -10000 || 10000 < delay_change) {
179 LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
180 LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp
181 << ", received time " << old_packet.timestamp;
182 LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp
183 << ", received time " << new_packet.timestamp;
184 LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
185 << static_cast<double>(recv_time_diff) / 1000000 << "s";
186 LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
187 << static_cast<double>(send_time_diff) /
188 kVideoSampleRate
189 << "s";
190 }
tereliusccbbf8d2016-08-10 07:34:28 -0700191 return delay_change;
192 }
193 };
194};
195
196template <typename Extractor>
197class Accumulated {
198 public:
199 using DataType = typename Extractor::DataType;
200 using ResultType = typename Extractor::ResultType;
201 ResultType operator()(const DataType& old_packet,
202 const DataType& new_packet) {
203 sum += extract(old_packet, new_packet);
204 return sum;
205 }
206
207 private:
208 Extractor extract;
209 ResultType sum = 0;
210};
211
terelius6addf492016-08-23 17:34:07 -0700212// For each element in data, use |Extractor| to extract a y-coordinate and
213// store the result in a TimeSeries.
214template <typename Extractor>
215void Pointwise(const std::vector<typename Extractor::DataType>& data,
216 uint64_t begin_time,
217 TimeSeries* result) {
218 Extractor extract;
219 for (size_t i = 0; i < data.size(); i++) {
220 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
221 float y = extract(data[i]);
222 result->points.emplace_back(x, y);
223 }
224}
225
226// For each pair of adjacent elements in |data|, use |Extractor| to extract a
227// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
228// will be the time of the second element in the pair.
tereliusccbbf8d2016-08-10 07:34:28 -0700229template <typename Extractor>
230void Pairwise(const std::vector<typename Extractor::DataType>& data,
231 uint64_t begin_time,
232 TimeSeries* result) {
233 Extractor extract;
234 for (size_t i = 1; i < data.size(); i++) {
235 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
236 float y = extract(data[i - 1], data[i]);
237 result->points.emplace_back(x, y);
238 }
239}
240
terelius6addf492016-08-23 17:34:07 -0700241// Calculates a moving average of |data| and stores the result in a TimeSeries.
242// A data point is generated every |step| microseconds from |begin_time|
243// to |end_time|. The value of each data point is the average of the data
244// during the preceeding |window_duration_us| microseconds.
245template <typename Extractor>
246void MovingAverage(const std::vector<typename Extractor::DataType>& data,
247 uint64_t begin_time,
248 uint64_t end_time,
249 uint64_t window_duration_us,
250 uint64_t step,
251 float y_scaling,
252 webrtc::plotting::TimeSeries* result) {
253 size_t window_index_begin = 0;
254 size_t window_index_end = 0;
255 typename Extractor::ResultType sum_in_window = 0;
256 Extractor extract;
257
258 for (uint64_t t = begin_time; t < end_time + step; t += step) {
259 while (window_index_end < data.size() &&
260 data[window_index_end].timestamp < t) {
261 sum_in_window += extract(data[window_index_end]);
262 ++window_index_end;
263 }
264 while (window_index_begin < data.size() &&
265 data[window_index_begin].timestamp < t - window_duration_us) {
266 sum_in_window -= extract(data[window_index_begin]);
267 ++window_index_begin;
268 }
269 float window_duration_s = static_cast<float>(window_duration_us) / 1000000;
270 float x = static_cast<float>(t - begin_time) / 1000000;
271 float y = sum_in_window / window_duration_s * y_scaling;
272 result->points.emplace_back(x, y);
273 }
274}
275
terelius54ce6802016-07-13 06:44:41 -0700276} // namespace
277
terelius54ce6802016-07-13 06:44:41 -0700278EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log)
279 : parsed_log_(log), window_duration_(250000), step_(10000) {
280 uint64_t first_timestamp = std::numeric_limits<uint64_t>::max();
281 uint64_t last_timestamp = std::numeric_limits<uint64_t>::min();
terelius88e64e52016-07-19 01:51:06 -0700282
Stefan Holmer13181032016-07-29 14:48:54 +0200283 // Maps a stream identifier consisting of ssrc and direction
terelius88e64e52016-07-19 01:51:06 -0700284 // to the header extensions used by that stream,
285 std::map<StreamId, RtpHeaderExtensionMap> extension_maps;
286
287 PacketDirection direction;
terelius88e64e52016-07-19 01:51:06 -0700288 uint8_t header[IP_PACKET_SIZE];
289 size_t header_length;
290 size_t total_length;
291
ivocaac9d6f2016-09-22 07:01:47 -0700292 // Make a default extension map for streams without configuration information.
293 // TODO(ivoc): Once configuration of audio streams is stored in the event log,
294 // this can be removed. Tracking bug: webrtc:6399
295 RtpHeaderExtensionMap default_extension_map = GetDefaultHeaderExtensionMap();
296
terelius54ce6802016-07-13 06:44:41 -0700297 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
298 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
terelius88e64e52016-07-19 01:51:06 -0700299 if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT &&
300 event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT &&
301 event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT &&
terelius88c1d2b2016-08-01 05:20:33 -0700302 event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT &&
303 event_type != ParsedRtcEventLog::LOG_START &&
304 event_type != ParsedRtcEventLog::LOG_END) {
terelius88e64e52016-07-19 01:51:06 -0700305 uint64_t timestamp = parsed_log_.GetTimestamp(i);
306 first_timestamp = std::min(first_timestamp, timestamp);
307 last_timestamp = std::max(last_timestamp, timestamp);
308 }
309
310 switch (parsed_log_.GetEventType(i)) {
311 case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: {
312 VideoReceiveStream::Config config(nullptr);
313 parsed_log_.GetVideoReceiveConfig(i, &config);
Stefan Holmer13181032016-07-29 14:48:54 +0200314 StreamId stream(config.rtp.remote_ssrc, kIncomingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800315 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp.extensions);
terelius0740a202016-08-08 10:21:04 -0700316 video_ssrcs_.insert(stream);
brandtr14742122017-01-27 04:53:07 -0800317 StreamId rtx_stream(config.rtp.rtx_ssrc, kIncomingPacket);
318 extension_maps[rtx_stream] =
319 RtpHeaderExtensionMap(config.rtp.extensions);
320 video_ssrcs_.insert(rtx_stream);
321 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700322 break;
323 }
324 case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: {
325 VideoSendStream::Config config(nullptr);
326 parsed_log_.GetVideoSendConfig(i, &config);
327 for (auto ssrc : config.rtp.ssrcs) {
Stefan Holmer13181032016-07-29 14:48:54 +0200328 StreamId stream(ssrc, kOutgoingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800329 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp.extensions);
terelius0740a202016-08-08 10:21:04 -0700330 video_ssrcs_.insert(stream);
stefan6a850c32016-07-29 10:28:08 -0700331 }
332 for (auto ssrc : config.rtp.rtx.ssrcs) {
terelius0740a202016-08-08 10:21:04 -0700333 StreamId rtx_stream(ssrc, kOutgoingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800334 extension_maps[rtx_stream] =
335 RtpHeaderExtensionMap(config.rtp.extensions);
terelius0740a202016-08-08 10:21:04 -0700336 video_ssrcs_.insert(rtx_stream);
337 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700338 }
339 break;
340 }
341 case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: {
342 AudioReceiveStream::Config config;
ivoce0928d82016-10-10 05:12:51 -0700343 parsed_log_.GetAudioReceiveConfig(i, &config);
344 StreamId stream(config.rtp.remote_ssrc, kIncomingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800345 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp.extensions);
ivoce0928d82016-10-10 05:12:51 -0700346 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700347 break;
348 }
349 case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: {
350 AudioSendStream::Config config(nullptr);
ivoce0928d82016-10-10 05:12:51 -0700351 parsed_log_.GetAudioSendConfig(i, &config);
352 StreamId stream(config.rtp.ssrc, kOutgoingPacket);
danilchap4aecc582016-11-15 09:21:00 -0800353 extension_maps[stream] = RtpHeaderExtensionMap(config.rtp.extensions);
ivoce0928d82016-10-10 05:12:51 -0700354 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700355 break;
356 }
357 case ParsedRtcEventLog::RTP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200358 MediaType media_type;
terelius88e64e52016-07-19 01:51:06 -0700359 parsed_log_.GetRtpHeader(i, &direction, &media_type, header,
360 &header_length, &total_length);
361 // Parse header to get SSRC.
362 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
363 RTPHeader parsed_header;
364 rtp_parser.Parse(&parsed_header);
Stefan Holmer13181032016-07-29 14:48:54 +0200365 StreamId stream(parsed_header.ssrc, direction);
terelius88e64e52016-07-19 01:51:06 -0700366 // Look up the extension_map and parse it again to get the extensions.
367 if (extension_maps.count(stream) == 1) {
368 RtpHeaderExtensionMap* extension_map = &extension_maps[stream];
369 rtp_parser.Parse(&parsed_header, extension_map);
ivocaac9d6f2016-09-22 07:01:47 -0700370 } else {
371 // Use the default extension map.
372 // TODO(ivoc): Once configuration of audio streams is stored in the
373 // event log, this can be removed.
374 // Tracking bug: webrtc:6399
375 rtp_parser.Parse(&parsed_header, &default_extension_map);
terelius88e64e52016-07-19 01:51:06 -0700376 }
377 uint64_t timestamp = parsed_log_.GetTimestamp(i);
378 rtp_packets_[stream].push_back(
Stefan Holmer13181032016-07-29 14:48:54 +0200379 LoggedRtpPacket(timestamp, parsed_header, total_length));
terelius88e64e52016-07-19 01:51:06 -0700380 break;
381 }
382 case ParsedRtcEventLog::RTCP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200383 uint8_t packet[IP_PACKET_SIZE];
384 MediaType media_type;
385 parsed_log_.GetRtcpPacket(i, &direction, &media_type, packet,
386 &total_length);
387
danilchapbf369fe2016-10-07 07:39:54 -0700388 // Currently feedback is logged twice, both for audio and video.
389 // Only act on one of them.
stefane372d3c2017-02-02 08:04:18 -0800390 if (media_type == MediaType::AUDIO || media_type == MediaType::ANY) {
danilchapbf369fe2016-10-07 07:39:54 -0700391 rtcp::CommonHeader header;
392 const uint8_t* packet_end = packet + total_length;
393 for (const uint8_t* block = packet; block < packet_end;
394 block = header.NextPacket()) {
395 RTC_CHECK(header.Parse(block, packet_end - block));
396 if (header.type() == rtcp::TransportFeedback::kPacketType &&
397 header.fmt() == rtcp::TransportFeedback::kFeedbackMessageType) {
398 std::unique_ptr<rtcp::TransportFeedback> rtcp_packet(
399 new rtcp::TransportFeedback());
400 if (rtcp_packet->Parse(header)) {
401 uint32_t ssrc = rtcp_packet->sender_ssrc();
Stefan Holmer13181032016-07-29 14:48:54 +0200402 StreamId stream(ssrc, direction);
403 uint64_t timestamp = parsed_log_.GetTimestamp(i);
404 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
405 timestamp, kRtcpTransportFeedback, std::move(rtcp_packet)));
406 }
stefane372d3c2017-02-02 08:04:18 -0800407 } else if (header.type() == rtcp::SenderReport::kPacketType) {
408 std::unique_ptr<rtcp::SenderReport> rtcp_packet(
409 new rtcp::SenderReport());
410 if (rtcp_packet->Parse(header)) {
411 uint32_t ssrc = rtcp_packet->sender_ssrc();
412 StreamId stream(ssrc, direction);
413 uint64_t timestamp = parsed_log_.GetTimestamp(i);
414 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
415 timestamp, kRtcpSr, std::move(rtcp_packet)));
416 }
417 } else if (header.type() == rtcp::ReceiverReport::kPacketType) {
418 std::unique_ptr<rtcp::ReceiverReport> rtcp_packet(
419 new rtcp::ReceiverReport());
420 if (rtcp_packet->Parse(header)) {
421 uint32_t ssrc = rtcp_packet->sender_ssrc();
422 StreamId stream(ssrc, direction);
423 uint64_t timestamp = parsed_log_.GetTimestamp(i);
424 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
425 timestamp, kRtcpRr, std::move(rtcp_packet)));
426 }
Stefan Holmer13181032016-07-29 14:48:54 +0200427 }
Stefan Holmer13181032016-07-29 14:48:54 +0200428 }
Stefan Holmer13181032016-07-29 14:48:54 +0200429 }
terelius88e64e52016-07-19 01:51:06 -0700430 break;
431 }
432 case ParsedRtcEventLog::LOG_START: {
433 break;
434 }
435 case ParsedRtcEventLog::LOG_END: {
436 break;
437 }
terelius424e6cf2017-02-20 05:14:41 -0800438 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: {
439 break;
440 }
441 case ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE: {
442 LossBasedBweUpdate bwe_update;
terelius8058e582016-07-25 01:32:41 -0700443 bwe_update.timestamp = parsed_log_.GetTimestamp(i);
terelius424e6cf2017-02-20 05:14:41 -0800444 parsed_log_.GetLossBasedBweUpdate(i, &bwe_update.new_bitrate,
445 &bwe_update.fraction_loss,
446 &bwe_update.expected_packets);
terelius8058e582016-07-25 01:32:41 -0700447 bwe_loss_updates_.push_back(bwe_update);
terelius88e64e52016-07-19 01:51:06 -0700448 break;
449 }
terelius424e6cf2017-02-20 05:14:41 -0800450 case ParsedRtcEventLog::DELAY_BASED_BWE_UPDATE: {
451 break;
452 }
minyue4b7c9522017-01-24 04:54:59 -0800453 case ParsedRtcEventLog::AUDIO_NETWORK_ADAPTATION_EVENT: {
michaelt6e5b2192017-02-22 07:33:27 -0800454 AudioNetworkAdaptationEvent ana_event;
455 ana_event.timestamp = parsed_log_.GetTimestamp(i);
456 parsed_log_.GetAudioNetworkAdaptation(i, &ana_event.config);
457 audio_network_adaptation_events_.push_back(ana_event);
minyue4b7c9522017-01-24 04:54:59 -0800458 break;
459 }
terelius88e64e52016-07-19 01:51:06 -0700460 case ParsedRtcEventLog::UNKNOWN_EVENT: {
461 break;
462 }
463 }
terelius54ce6802016-07-13 06:44:41 -0700464 }
terelius88e64e52016-07-19 01:51:06 -0700465
terelius54ce6802016-07-13 06:44:41 -0700466 if (last_timestamp < first_timestamp) {
467 // No useful events in the log.
468 first_timestamp = last_timestamp = 0;
469 }
470 begin_time_ = first_timestamp;
471 end_time_ = last_timestamp;
tereliusdc35dcd2016-08-01 12:03:27 -0700472 call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000;
terelius54ce6802016-07-13 06:44:41 -0700473}
474
Stefan Holmer13181032016-07-29 14:48:54 +0200475class BitrateObserver : public CongestionController::Observer,
476 public RemoteBitrateObserver {
477 public:
478 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
479
minyue78b4d562016-11-30 04:47:39 -0800480 // TODO(minyue): remove this when old OnNetworkChanged is deprecated. See
481 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6796
482 using CongestionController::Observer::OnNetworkChanged;
483
Stefan Holmer13181032016-07-29 14:48:54 +0200484 void OnNetworkChanged(uint32_t bitrate_bps,
485 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800486 int64_t rtt_ms,
487 int64_t probing_interval_ms) override {
Stefan Holmer13181032016-07-29 14:48:54 +0200488 last_bitrate_bps_ = bitrate_bps;
489 bitrate_updated_ = true;
490 }
491
492 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
493 uint32_t bitrate) override {}
494
495 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
496 bool GetAndResetBitrateUpdated() {
497 bool bitrate_updated = bitrate_updated_;
498 bitrate_updated_ = false;
499 return bitrate_updated;
500 }
501
502 private:
503 uint32_t last_bitrate_bps_;
504 bool bitrate_updated_;
505};
506
Stefan Holmer99f8e082016-09-09 13:37:50 +0200507bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700508 return rtx_ssrcs_.count(stream_id) == 1;
509}
510
Stefan Holmer99f8e082016-09-09 13:37:50 +0200511bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700512 return video_ssrcs_.count(stream_id) == 1;
513}
514
Stefan Holmer99f8e082016-09-09 13:37:50 +0200515bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700516 return audio_ssrcs_.count(stream_id) == 1;
517}
518
Stefan Holmer99f8e082016-09-09 13:37:50 +0200519std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const {
520 std::stringstream name;
521 if (IsAudioSsrc(stream_id)) {
522 name << "Audio ";
523 } else if (IsVideoSsrc(stream_id)) {
524 name << "Video ";
525 } else {
526 name << "Unknown ";
527 }
528 if (IsRtxSsrc(stream_id))
529 name << "RTX ";
ivocaac9d6f2016-09-22 07:01:47 -0700530 if (stream_id.GetDirection() == kIncomingPacket) {
531 name << "(In) ";
532 } else {
533 name << "(Out) ";
534 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200535 name << SsrcToString(stream_id.GetSsrc());
536 return name.str();
537}
538
michaelt6e5b2192017-02-22 07:33:27 -0800539void EventLogAnalyzer::FillAudioEncoderTimeSeries(
540 Plot* plot,
541 rtc::FunctionView<rtc::Optional<float>(
542 const AudioNetworkAdaptationEvent& ana_event)> get_y) const {
543 plot->series_list_.push_back(TimeSeries());
544 plot->series_list_.back().style = LINE_DOT_GRAPH;
545 for (auto& ana_event : audio_network_adaptation_events_) {
546 rtc::Optional<float> y = get_y(ana_event);
547 if (y) {
548 float x = static_cast<float>(ana_event.timestamp - begin_time_) / 1000000;
549 plot->series_list_.back().points.emplace_back(x, *y);
550 }
551 }
552}
553
terelius54ce6802016-07-13 06:44:41 -0700554void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
555 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700556 for (auto& kv : rtp_packets_) {
557 StreamId stream_id = kv.first;
558 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
559 // Filter on direction and SSRC.
560 if (stream_id.GetDirection() != desired_direction ||
561 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
562 continue;
terelius54ce6802016-07-13 06:44:41 -0700563 }
terelius54ce6802016-07-13 06:44:41 -0700564
terelius6addf492016-08-23 17:34:07 -0700565 TimeSeries time_series;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200566 time_series.label = GetStreamName(stream_id);
terelius6addf492016-08-23 17:34:07 -0700567 time_series.style = BAR_GRAPH;
568 Pointwise<PacketSizeBytes>(packet_stream, begin_time_, &time_series);
569 plot->series_list_.push_back(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700570 }
571
tereliusdc35dcd2016-08-01 12:03:27 -0700572 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
573 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
574 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700575 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700576 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700577 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700578 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700579 }
580}
581
philipelccd74892016-09-05 02:46:25 -0700582template <typename T>
583void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
584 PacketDirection desired_direction,
585 Plot* plot,
586 const std::map<StreamId, std::vector<T>>& packets,
587 const std::string& label_prefix) {
588 for (auto& kv : packets) {
589 StreamId stream_id = kv.first;
590 const std::vector<T>& packet_stream = kv.second;
591 // Filter on direction and SSRC.
592 if (stream_id.GetDirection() != desired_direction ||
593 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
594 continue;
595 }
596
597 TimeSeries time_series;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200598 time_series.label = label_prefix + " " + GetStreamName(stream_id);
terelius77f05802017-02-01 06:34:53 -0800599 time_series.style = LINE_STEP_GRAPH;
philipelccd74892016-09-05 02:46:25 -0700600
601 for (size_t i = 0; i < packet_stream.size(); i++) {
602 float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) /
603 1000000;
philipelccd74892016-09-05 02:46:25 -0700604 time_series.points.emplace_back(x, i + 1);
605 }
606
607 plot->series_list_.push_back(std::move(time_series));
608 }
609}
610
611void EventLogAnalyzer::CreateAccumulatedPacketsGraph(
612 PacketDirection desired_direction,
613 Plot* plot) {
614 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_,
615 "RTP");
616 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_,
617 "RTCP");
618
619 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
620 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
621 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
622 plot->SetTitle("Accumulated Incoming RTP/RTCP packets");
623 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
624 plot->SetTitle("Accumulated Outgoing RTP/RTCP packets");
625 }
626}
627
terelius54ce6802016-07-13 06:44:41 -0700628// For each SSRC, plot the time between the consecutive playouts.
629void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
630 std::map<uint32_t, TimeSeries> time_series;
631 std::map<uint32_t, uint64_t> last_playout;
632
633 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700634
635 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
636 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
637 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
638 parsed_log_.GetAudioPlayout(i, &ssrc);
639 uint64_t timestamp = parsed_log_.GetTimestamp(i);
640 if (MatchingSsrc(ssrc, desired_ssrc_)) {
641 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
642 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
643 if (time_series[ssrc].points.size() == 0) {
644 // There were no previusly logged playout for this SSRC.
645 // Generate a point, but place it on the x-axis.
646 y = 0;
647 }
terelius54ce6802016-07-13 06:44:41 -0700648 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
649 last_playout[ssrc] = timestamp;
650 }
651 }
652 }
653
654 // Set labels and put in graph.
655 for (auto& kv : time_series) {
656 kv.second.label = SsrcToString(kv.first);
657 kv.second.style = BAR_GRAPH;
tereliusdc35dcd2016-08-01 12:03:27 -0700658 plot->series_list_.push_back(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700659 }
660
tereliusdc35dcd2016-08-01 12:03:27 -0700661 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
662 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
663 kTopMargin);
664 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700665}
666
ivocaac9d6f2016-09-22 07:01:47 -0700667// For audio SSRCs, plot the audio level.
668void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) {
669 std::map<StreamId, TimeSeries> time_series;
670
671 for (auto& kv : rtp_packets_) {
672 StreamId stream_id = kv.first;
673 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
674 // TODO(ivoc): When audio send/receive configs are stored in the event
675 // log, a check should be added here to only process audio
676 // streams. Tracking bug: webrtc:6399
677 for (auto& packet : packet_stream) {
678 if (packet.header.extension.hasAudioLevel) {
679 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
680 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
681 // Here we convert it to dBov.
682 float y = static_cast<float>(-packet.header.extension.audioLevel);
683 time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y));
684 }
685 }
686 }
687
688 for (auto& series : time_series) {
689 series.second.label = GetStreamName(series.first);
690 series.second.style = LINE_GRAPH;
691 plot->series_list_.push_back(std::move(series.second));
692 }
693
694 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
ivocbf676632016-11-24 08:30:34 -0800695 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin,
ivocaac9d6f2016-09-22 07:01:47 -0700696 kTopMargin);
697 plot->SetTitle("Audio level");
698}
699
terelius54ce6802016-07-13 06:44:41 -0700700// For each SSRC, plot the time between the consecutive playouts.
701void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700702 for (auto& kv : rtp_packets_) {
703 StreamId stream_id = kv.first;
704 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
705 // Filter on direction and SSRC.
706 if (stream_id.GetDirection() != kIncomingPacket ||
707 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
708 continue;
terelius54ce6802016-07-13 06:44:41 -0700709 }
terelius54ce6802016-07-13 06:44:41 -0700710
terelius6addf492016-08-23 17:34:07 -0700711 TimeSeries time_series;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200712 time_series.label = GetStreamName(stream_id);
terelius6addf492016-08-23 17:34:07 -0700713 time_series.style = BAR_GRAPH;
714 Pairwise<SequenceNumberDiff>(packet_stream, begin_time_, &time_series);
715 plot->series_list_.push_back(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700716 }
717
tereliusdc35dcd2016-08-01 12:03:27 -0700718 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
719 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
720 kTopMargin);
721 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700722}
723
Stefan Holmer99f8e082016-09-09 13:37:50 +0200724void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
725 for (auto& kv : rtp_packets_) {
726 StreamId stream_id = kv.first;
727 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
728 // Filter on direction and SSRC.
729 if (stream_id.GetDirection() != kIncomingPacket ||
terelius4c9b4af2017-01-30 08:44:51 -0800730 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
731 packet_stream.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200732 continue;
733 }
734
735 TimeSeries time_series;
736 time_series.label = GetStreamName(stream_id);
737 time_series.style = LINE_DOT_GRAPH;
738 const uint64_t kWindowUs = 1000000;
terelius4c9b4af2017-01-30 08:44:51 -0800739 const uint64_t kStep = 1000000;
740 SequenceNumberUnwrapper unwrapper_;
741 SequenceNumberUnwrapper prior_unwrapper_;
742 size_t window_index_begin = 0;
743 size_t window_index_end = 0;
744 int64_t highest_seq_number =
745 unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
746 int64_t highest_prior_seq_number =
747 prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
748
749 for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) {
750 while (window_index_end < packet_stream.size() &&
751 packet_stream[window_index_end].timestamp < t) {
752 int64_t sequence_number = unwrapper_.Unwrap(
753 packet_stream[window_index_end].header.sequenceNumber);
754 highest_seq_number = std::max(highest_seq_number, sequence_number);
755 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200756 }
terelius4c9b4af2017-01-30 08:44:51 -0800757 while (window_index_begin < packet_stream.size() &&
758 packet_stream[window_index_begin].timestamp < t - kWindowUs) {
759 int64_t sequence_number = prior_unwrapper_.Unwrap(
760 packet_stream[window_index_begin].header.sequenceNumber);
761 highest_prior_seq_number =
762 std::max(highest_prior_seq_number, sequence_number);
763 ++window_index_begin;
764 }
765 float x = static_cast<float>(t - begin_time_) / 1000000;
766 int64_t expected_packets = highest_seq_number - highest_prior_seq_number;
767 if (expected_packets > 0) {
768 int64_t received_packets = window_index_end - window_index_begin;
769 int64_t lost_packets = expected_packets - received_packets;
770 float y = static_cast<float>(lost_packets) / expected_packets * 100;
771 time_series.points.emplace_back(x, y);
772 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200773 }
774 plot->series_list_.push_back(std::move(time_series));
775 }
776
777 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
778 plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin,
779 kTopMargin);
780 plot->SetTitle("Estimated incoming loss rate");
781}
782
terelius54ce6802016-07-13 06:44:41 -0700783void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700784 for (auto& kv : rtp_packets_) {
785 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700786 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700787 // Filter on direction and SSRC.
788 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200789 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
790 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
791 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700792 continue;
793 }
terelius54ce6802016-07-13 06:44:41 -0700794
tereliusccbbf8d2016-08-10 07:34:28 -0700795 TimeSeries capture_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200796 capture_time_data.label = GetStreamName(stream_id) + " capture-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700797 capture_time_data.style = BAR_GRAPH;
798 Pairwise<NetworkDelayDiff::CaptureTime>(packet_stream, begin_time_,
799 &capture_time_data);
800 plot->series_list_.push_back(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700801
tereliusccbbf8d2016-08-10 07:34:28 -0700802 TimeSeries send_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200803 send_time_data.label = GetStreamName(stream_id) + " abs-send-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700804 send_time_data.style = BAR_GRAPH;
805 Pairwise<NetworkDelayDiff::AbsSendTime>(packet_stream, begin_time_,
806 &send_time_data);
807 plot->series_list_.push_back(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700808 }
809
tereliusdc35dcd2016-08-01 12:03:27 -0700810 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
811 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
812 kTopMargin);
813 plot->SetTitle("Network latency change between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700814}
815
816void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700817 for (auto& kv : rtp_packets_) {
818 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700819 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700820 // Filter on direction and SSRC.
821 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200822 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
823 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
824 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700825 continue;
826 }
terelius54ce6802016-07-13 06:44:41 -0700827
tereliusccbbf8d2016-08-10 07:34:28 -0700828 TimeSeries capture_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200829 capture_time_data.label = GetStreamName(stream_id) + " capture-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700830 capture_time_data.style = LINE_GRAPH;
831 Pairwise<Accumulated<NetworkDelayDiff::CaptureTime>>(
832 packet_stream, begin_time_, &capture_time_data);
833 plot->series_list_.push_back(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700834
tereliusccbbf8d2016-08-10 07:34:28 -0700835 TimeSeries send_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200836 send_time_data.label = GetStreamName(stream_id) + " abs-send-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700837 send_time_data.style = LINE_GRAPH;
838 Pairwise<Accumulated<NetworkDelayDiff::AbsSendTime>>(
839 packet_stream, begin_time_, &send_time_data);
840 plot->series_list_.push_back(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700841 }
842
tereliusdc35dcd2016-08-01 12:03:27 -0700843 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
844 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
845 kTopMargin);
846 plot->SetTitle("Accumulated network latency change");
terelius54ce6802016-07-13 06:44:41 -0700847}
848
tereliusf736d232016-08-04 10:00:11 -0700849// Plot the fraction of packets lost (as perceived by the loss-based BWE).
850void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
851 plot->series_list_.push_back(TimeSeries());
852 for (auto& bwe_update : bwe_loss_updates_) {
853 float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
854 float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100;
855 plot->series_list_.back().points.emplace_back(x, y);
856 }
857 plot->series_list_.back().label = "Fraction lost";
858 plot->series_list_.back().style = LINE_DOT_GRAPH;
859
860 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
861 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
862 kTopMargin);
863 plot->SetTitle("Reported packet loss");
864}
865
terelius54ce6802016-07-13 06:44:41 -0700866// Plot the total bandwidth used by all RTP streams.
867void EventLogAnalyzer::CreateTotalBitrateGraph(
868 PacketDirection desired_direction,
869 Plot* plot) {
870 struct TimestampSize {
871 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
872 uint64_t timestamp;
873 size_t size;
874 };
875 std::vector<TimestampSize> packets;
876
877 PacketDirection direction;
878 size_t total_length;
879
880 // Extract timestamps and sizes for the relevant packets.
881 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
882 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
883 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
884 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, nullptr,
885 &total_length);
886 if (direction == desired_direction) {
887 uint64_t timestamp = parsed_log_.GetTimestamp(i);
888 packets.push_back(TimestampSize(timestamp, total_length));
889 }
890 }
891 }
892
893 size_t window_index_begin = 0;
894 size_t window_index_end = 0;
895 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700896
897 // Calculate a moving average of the bitrate and store in a TimeSeries.
tereliusdc35dcd2016-08-01 12:03:27 -0700898 plot->series_list_.push_back(TimeSeries());
terelius54ce6802016-07-13 06:44:41 -0700899 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
900 while (window_index_end < packets.size() &&
901 packets[window_index_end].timestamp < time) {
902 bytes_in_window += packets[window_index_end].size;
terelius6addf492016-08-23 17:34:07 -0700903 ++window_index_end;
terelius54ce6802016-07-13 06:44:41 -0700904 }
905 while (window_index_begin < packets.size() &&
906 packets[window_index_begin].timestamp < time - window_duration_) {
907 RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window);
908 bytes_in_window -= packets[window_index_begin].size;
terelius6addf492016-08-23 17:34:07 -0700909 ++window_index_begin;
terelius54ce6802016-07-13 06:44:41 -0700910 }
911 float window_duration_in_seconds =
912 static_cast<float>(window_duration_) / 1000000;
913 float x = static_cast<float>(time - begin_time_) / 1000000;
914 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
tereliusdc35dcd2016-08-01 12:03:27 -0700915 plot->series_list_.back().points.push_back(TimeSeriesPoint(x, y));
terelius54ce6802016-07-13 06:44:41 -0700916 }
917
918 // Set labels.
919 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700920 plot->series_list_.back().label = "Incoming bitrate";
terelius54ce6802016-07-13 06:44:41 -0700921 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700922 plot->series_list_.back().label = "Outgoing bitrate";
terelius54ce6802016-07-13 06:44:41 -0700923 }
tereliusdc35dcd2016-08-01 12:03:27 -0700924 plot->series_list_.back().style = LINE_GRAPH;
terelius54ce6802016-07-13 06:44:41 -0700925
terelius8058e582016-07-25 01:32:41 -0700926 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
927 if (desired_direction == kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700928 plot->series_list_.push_back(TimeSeries());
terelius8058e582016-07-25 01:32:41 -0700929 for (auto& bwe_update : bwe_loss_updates_) {
930 float x =
931 static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
932 float y = static_cast<float>(bwe_update.new_bitrate) / 1000;
tereliusdc35dcd2016-08-01 12:03:27 -0700933 plot->series_list_.back().points.emplace_back(x, y);
terelius8058e582016-07-25 01:32:41 -0700934 }
tereliusdc35dcd2016-08-01 12:03:27 -0700935 plot->series_list_.back().label = "Loss-based estimate";
terelius77f05802017-02-01 06:34:53 -0800936 plot->series_list_.back().style = LINE_STEP_GRAPH;
terelius8058e582016-07-25 01:32:41 -0700937 }
tereliusdc35dcd2016-08-01 12:03:27 -0700938 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
939 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700940 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700941 plot->SetTitle("Incoming RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -0700942 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700943 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -0700944 }
945}
946
947// For each SSRC, plot the bandwidth used by that stream.
948void EventLogAnalyzer::CreateStreamBitrateGraph(
949 PacketDirection desired_direction,
950 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700951 for (auto& kv : rtp_packets_) {
952 StreamId stream_id = kv.first;
953 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
954 // Filter on direction and SSRC.
955 if (stream_id.GetDirection() != desired_direction ||
956 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
957 continue;
terelius54ce6802016-07-13 06:44:41 -0700958 }
959
terelius6addf492016-08-23 17:34:07 -0700960 TimeSeries time_series;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200961 time_series.label = GetStreamName(stream_id);
terelius6addf492016-08-23 17:34:07 -0700962 time_series.style = LINE_GRAPH;
963 double bytes_to_kilobits = 8.0 / 1000;
964 MovingAverage<PacketSizeBytes>(packet_stream, begin_time_, end_time_,
965 window_duration_, step_, bytes_to_kilobits,
966 &time_series);
967 plot->series_list_.push_back(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700968 }
969
tereliusdc35dcd2016-08-01 12:03:27 -0700970 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
971 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700972 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700973 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -0700974 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700975 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -0700976 }
977}
978
tereliuse34c19c2016-08-15 08:47:14 -0700979void EventLogAnalyzer::CreateBweSimulationGraph(Plot* plot) {
Stefan Holmer13181032016-07-29 14:48:54 +0200980 std::map<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
981 std::map<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
982
983 for (const auto& kv : rtp_packets_) {
984 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
985 for (const LoggedRtpPacket& rtp_packet : kv.second)
986 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
987 }
988 }
989
990 for (const auto& kv : rtcp_packets_) {
991 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
992 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
993 incoming_rtcp.insert(
994 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
995 }
996 }
997
998 SimulatedClock clock(0);
999 BitrateObserver observer;
1000 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001001 PacketRouter packet_router;
1002 CongestionController cc(&clock, &observer, &observer, &null_event_log,
1003 &packet_router);
Stefan Holmer13181032016-07-29 14:48:54 +02001004 // TODO(holmer): Log the call config and use that here instead.
1005 static const uint32_t kDefaultStartBitrateBps = 300000;
1006 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1007
1008 TimeSeries time_series;
tereliuse34c19c2016-08-15 08:47:14 -07001009 time_series.label = "Delay-based estimate";
Stefan Holmer13181032016-07-29 14:48:54 +02001010 time_series.style = LINE_DOT_GRAPH;
Stefan Holmer60e43462016-09-07 09:58:20 +02001011 TimeSeries acked_time_series;
1012 acked_time_series.label = "Acked bitrate";
1013 acked_time_series.style = LINE_DOT_GRAPH;
Stefan Holmer13181032016-07-29 14:48:54 +02001014
1015 auto rtp_iterator = outgoing_rtp.begin();
1016 auto rtcp_iterator = incoming_rtcp.begin();
1017
1018 auto NextRtpTime = [&]() {
1019 if (rtp_iterator != outgoing_rtp.end())
1020 return static_cast<int64_t>(rtp_iterator->first);
1021 return std::numeric_limits<int64_t>::max();
1022 };
1023
1024 auto NextRtcpTime = [&]() {
1025 if (rtcp_iterator != incoming_rtcp.end())
1026 return static_cast<int64_t>(rtcp_iterator->first);
1027 return std::numeric_limits<int64_t>::max();
1028 };
1029
1030 auto NextProcessTime = [&]() {
1031 if (rtcp_iterator != incoming_rtcp.end() ||
1032 rtp_iterator != outgoing_rtp.end()) {
1033 return clock.TimeInMicroseconds() +
1034 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
1035 }
1036 return std::numeric_limits<int64_t>::max();
1037 };
1038
Stefan Holmer492ee282016-10-27 17:19:20 +02001039 RateStatistics acked_bitrate(250, 8000);
Stefan Holmer60e43462016-09-07 09:58:20 +02001040
Stefan Holmer13181032016-07-29 14:48:54 +02001041 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
Stefan Holmer492ee282016-10-27 17:19:20 +02001042 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001043 while (time_us != std::numeric_limits<int64_t>::max()) {
1044 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1045 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001046 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001047 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1048 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001049 TransportFeedbackObserver* observer = cc.GetTransportFeedbackObserver();
1050 observer->OnTransportFeedback(*static_cast<rtcp::TransportFeedback*>(
1051 rtcp.packet.get()));
1052 std::vector<PacketInfo> feedback =
1053 observer->GetTransportFeedbackVector();
1054 rtc::Optional<uint32_t> bitrate_bps;
1055 if (!feedback.empty()) {
1056 for (const PacketInfo& packet : feedback)
1057 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1058 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1059 }
1060 uint32_t y = 0;
1061 if (bitrate_bps)
1062 y = *bitrate_bps / 1000;
1063 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1064 1000000;
1065 acked_time_series.points.emplace_back(x, y);
Stefan Holmer13181032016-07-29 14:48:54 +02001066 }
1067 ++rtcp_iterator;
1068 }
1069 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001070 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001071 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1072 if (rtp.header.extension.hasTransportSequenceNumber) {
1073 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
1074 cc.GetTransportFeedbackObserver()->AddPacket(
stefana93d5ac2016-08-17 02:14:32 -07001075 rtp.header.extension.transportSequenceNumber, rtp.total_length,
philipelc7bf32a2017-02-17 03:59:43 -08001076 PacedPacketInfo::kNotAProbe);
Stefan Holmer13181032016-07-29 14:48:54 +02001077 rtc::SentPacket sent_packet(
1078 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1079 cc.OnSentPacket(sent_packet);
1080 }
1081 ++rtp_iterator;
1082 }
stefanc3de0332016-08-02 07:22:17 -07001083 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1084 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001085 cc.Process();
stefanc3de0332016-08-02 07:22:17 -07001086 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001087 if (observer.GetAndResetBitrateUpdated() ||
1088 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001089 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer13181032016-07-29 14:48:54 +02001090 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1091 1000000;
1092 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001093 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001094 }
1095 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1096 }
1097 // Add the data set to the plot.
tereliusdc35dcd2016-08-01 12:03:27 -07001098 plot->series_list_.push_back(std::move(time_series));
Stefan Holmer60e43462016-09-07 09:58:20 +02001099 plot->series_list_.push_back(std::move(acked_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001100
tereliusdc35dcd2016-08-01 12:03:27 -07001101 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1102 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1103 plot->SetTitle("Simulated BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001104}
1105
Stefan Holmer280de9e2016-09-30 10:06:51 +02001106// TODO(holmer): Remove once TransportFeedbackAdapter no longer needs a
1107// BitrateController.
1108class NullBitrateController : public BitrateController {
1109 public:
1110 ~NullBitrateController() override {}
1111 RtcpBandwidthObserver* CreateRtcpBandwidthObserver() override {
1112 return nullptr;
1113 }
1114 void SetStartBitrate(int start_bitrate_bps) override {}
1115 void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) override {}
1116 void SetBitrates(int start_bitrate_bps,
1117 int min_bitrate_bps,
1118 int max_bitrate_bps) override {}
1119 void ResetBitrates(int bitrate_bps,
1120 int min_bitrate_bps,
1121 int max_bitrate_bps) override {}
1122 void OnDelayBasedBweResult(const DelayBasedBwe::Result& result) override {}
1123 bool AvailableBandwidth(uint32_t* bandwidth) const override { return false; }
1124 void SetReservedBitrate(uint32_t reserved_bitrate_bps) override {}
1125 bool GetNetworkParameters(uint32_t* bitrate,
1126 uint8_t* fraction_loss,
1127 int64_t* rtt) override {
1128 return false;
1129 }
1130 int64_t TimeUntilNextProcess() override { return 0; }
1131 void Process() override {}
1132};
1133
tereliuse34c19c2016-08-15 08:47:14 -07001134void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanc3de0332016-08-02 07:22:17 -07001135 std::map<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1136 std::map<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
1137
1138 for (const auto& kv : rtp_packets_) {
1139 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1140 for (const LoggedRtpPacket& rtp_packet : kv.second)
1141 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1142 }
1143 }
1144
1145 for (const auto& kv : rtcp_packets_) {
1146 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1147 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1148 incoming_rtcp.insert(
1149 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1150 }
1151 }
1152
1153 SimulatedClock clock(0);
Stefan Holmer280de9e2016-09-30 10:06:51 +02001154 NullBitrateController null_controller;
terelius0baf55d2017-02-17 03:38:28 -08001155 TransportFeedbackAdapter feedback_adapter(nullptr, &clock, &null_controller);
stefan41aab322016-10-10 08:16:30 -07001156 feedback_adapter.InitBwe();
stefanc3de0332016-08-02 07:22:17 -07001157
1158 TimeSeries time_series;
1159 time_series.label = "Network Delay Change";
1160 time_series.style = LINE_DOT_GRAPH;
1161 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
1162
1163 auto rtp_iterator = outgoing_rtp.begin();
1164 auto rtcp_iterator = incoming_rtcp.begin();
1165
1166 auto NextRtpTime = [&]() {
1167 if (rtp_iterator != outgoing_rtp.end())
1168 return static_cast<int64_t>(rtp_iterator->first);
1169 return std::numeric_limits<int64_t>::max();
1170 };
1171
1172 auto NextRtcpTime = [&]() {
1173 if (rtcp_iterator != incoming_rtcp.end())
1174 return static_cast<int64_t>(rtcp_iterator->first);
1175 return std::numeric_limits<int64_t>::max();
1176 };
1177
1178 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
1179 while (time_us != std::numeric_limits<int64_t>::max()) {
1180 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1181 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
1182 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
1183 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1184 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001185 feedback_adapter.OnTransportFeedback(
1186 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
stefanc3de0332016-08-02 07:22:17 -07001187 std::vector<PacketInfo> feedback =
Stefan Holmer60e43462016-09-07 09:58:20 +02001188 feedback_adapter.GetTransportFeedbackVector();
stefanc3de0332016-08-02 07:22:17 -07001189 for (const PacketInfo& packet : feedback) {
1190 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1191 float x =
1192 static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1193 1000000;
1194 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
1195 time_series.points.emplace_back(x, y);
1196 }
1197 }
1198 ++rtcp_iterator;
1199 }
1200 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1201 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1202 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1203 if (rtp.header.extension.hasTransportSequenceNumber) {
1204 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
1205 feedback_adapter.AddPacket(rtp.header.extension.transportSequenceNumber,
philipelc7bf32a2017-02-17 03:59:43 -08001206 rtp.total_length,
1207 PacedPacketInfo::kNotAProbe);
stefanc3de0332016-08-02 07:22:17 -07001208 feedback_adapter.OnSentPacket(
1209 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1210 }
1211 ++rtp_iterator;
1212 }
1213 time_us = std::min(NextRtpTime(), NextRtcpTime());
1214 }
1215 // We assume that the base network delay (w/o queues) is the min delay
1216 // observed during the call.
1217 for (TimeSeriesPoint& point : time_series.points)
1218 point.y -= estimated_base_delay_ms;
1219 // Add the data set to the plot.
1220 plot->series_list_.push_back(std::move(time_series));
1221
1222 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1223 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1224 plot->SetTitle("Network Delay Change.");
1225}
stefan08383272016-12-20 08:51:52 -08001226
1227std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps()
1228 const {
1229 std::vector<std::pair<int64_t, int64_t>> timestamps;
1230 size_t largest_stream_size = 0;
1231 const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr;
1232 // Find the incoming video stream with the most number of packets that is
1233 // not rtx.
1234 for (const auto& kv : rtp_packets_) {
1235 if (kv.first.GetDirection() == kIncomingPacket &&
1236 video_ssrcs_.find(kv.first) != video_ssrcs_.end() &&
1237 rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() &&
1238 kv.second.size() > largest_stream_size) {
1239 largest_stream_size = kv.second.size();
1240 largest_video_stream = &kv.second;
1241 }
1242 }
1243 if (largest_video_stream == nullptr) {
1244 for (auto& packet : *largest_video_stream) {
1245 if (packet.header.markerBit) {
1246 int64_t capture_ms = packet.header.timestamp / 90.0;
1247 int64_t arrival_ms = packet.timestamp / 1000.0;
1248 timestamps.push_back(std::make_pair(capture_ms, arrival_ms));
1249 }
1250 }
1251 }
1252 return timestamps;
1253}
stefane372d3c2017-02-02 08:04:18 -08001254
1255void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) {
1256 for (const auto& kv : rtp_packets_) {
1257 const std::vector<LoggedRtpPacket>& rtp_packets = kv.second;
1258 StreamId stream_id = kv.first;
1259
1260 {
1261 TimeSeries timestamp_data;
1262 timestamp_data.label = GetStreamName(stream_id) + " capture-time";
1263 timestamp_data.style = LINE_DOT_GRAPH;
1264 for (LoggedRtpPacket packet : rtp_packets) {
1265 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1266 float y = packet.header.timestamp;
1267 timestamp_data.points.emplace_back(x, y);
1268 }
1269 plot->series_list_.push_back(std::move(timestamp_data));
1270 }
1271
1272 {
1273 auto kv = rtcp_packets_.find(stream_id);
1274 if (kv != rtcp_packets_.end()) {
1275 const auto& packets = kv->second;
1276 TimeSeries timestamp_data;
1277 timestamp_data.label = GetStreamName(stream_id) + " rtcp capture-time";
1278 timestamp_data.style = LINE_DOT_GRAPH;
1279 for (const LoggedRtcpPacket& rtcp : packets) {
1280 if (rtcp.type != kRtcpSr)
1281 continue;
1282 rtcp::SenderReport* sr;
1283 sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get());
1284 float x = static_cast<float>(rtcp.timestamp - begin_time_) / 1000000;
1285 float y = sr->rtp_timestamp();
1286 timestamp_data.points.emplace_back(x, y);
1287 }
1288 plot->series_list_.push_back(std::move(timestamp_data));
1289 }
1290 }
1291 }
1292
1293 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1294 plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin);
1295 plot->SetTitle("Timestamps");
1296}
michaelt6e5b2192017-02-22 07:33:27 -08001297
1298void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
1299 FillAudioEncoderTimeSeries(
1300 plot, [](const AudioNetworkAdaptationEvent& ana_event) {
1301 if (ana_event.config.bitrate_bps)
1302 return rtc::Optional<float>(
1303 static_cast<float>(*ana_event.config.bitrate_bps));
1304 return rtc::Optional<float>();
1305 });
1306 plot->series_list_.back().label = "Audio encoder target bitrate";
1307 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) {
1313 FillAudioEncoderTimeSeries(
1314 plot, [](const AudioNetworkAdaptationEvent& ana_event) {
1315 if (ana_event.config.frame_length_ms)
1316 return rtc::Optional<float>(
1317 static_cast<float>(*ana_event.config.frame_length_ms));
1318 return rtc::Optional<float>();
1319 });
1320 plot->series_list_.back().label = "Audio encoder frame length";
1321 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1322 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1323 plot->SetTitle("Reported audio encoder frame length");
1324}
1325
1326void EventLogAnalyzer::CreateAudioEncoderUplinkPacketLossFractionGraph(
1327 Plot* plot) {
1328 FillAudioEncoderTimeSeries(
1329 plot, [&](const AudioNetworkAdaptationEvent& ana_event) {
1330 if (ana_event.config.uplink_packet_loss_fraction)
1331 return rtc::Optional<float>(static_cast<float>(
1332 *ana_event.config.uplink_packet_loss_fraction));
1333 return rtc::Optional<float>();
1334 });
1335 plot->series_list_.back().label = "Audio encoder uplink packet loss fraction";
1336 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1337 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1338 kTopMargin);
1339 plot->SetTitle("Reported audio encoder lost packets");
1340}
1341
1342void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
1343 FillAudioEncoderTimeSeries(
1344 plot, [&](const AudioNetworkAdaptationEvent& ana_event) {
1345 if (ana_event.config.enable_fec)
1346 return rtc::Optional<float>(
1347 static_cast<float>(*ana_event.config.enable_fec));
1348 return rtc::Optional<float>();
1349 });
1350 plot->series_list_.back().label = "Audio encoder FEC";
1351 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1352 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1353 plot->SetTitle("Reported audio encoder FEC");
1354}
1355
1356void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
1357 FillAudioEncoderTimeSeries(
1358 plot, [&](const AudioNetworkAdaptationEvent& ana_event) {
1359 if (ana_event.config.enable_dtx)
1360 return rtc::Optional<float>(
1361 static_cast<float>(*ana_event.config.enable_dtx));
1362 return rtc::Optional<float>();
1363 });
1364 plot->series_list_.back().label = "Audio encoder DTX";
1365 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1366 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1367 plot->SetTitle("Reported audio encoder DTX");
1368}
1369
1370void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
1371 FillAudioEncoderTimeSeries(
1372 plot, [&](const AudioNetworkAdaptationEvent& ana_event) {
1373 if (ana_event.config.num_channels)
1374 return rtc::Optional<float>(
1375 static_cast<float>(*ana_event.config.num_channels));
1376 return rtc::Optional<float>();
1377 });
1378 plot->series_list_.back().label = "Audio encoder number of channels";
1379 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1380 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1381 kBottomMargin, kTopMargin);
1382 plot->SetTitle("Reported audio encoder number of channels");
1383}
terelius54ce6802016-07-13 06:44:41 -07001384} // namespace plotting
1385} // namespace webrtc