blob: 7797825e2a2536f1c3d735781acdeba5eb7db0a9 [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
kjellandera69d9732016-08-31 07:33:05 -070020#include "webrtc/api/call/audio_receive_stream.h"
21#include "webrtc/api/call/audio_send_stream.h"
terelius54ce6802016-07-13 06:44:41 -070022#include "webrtc/base/checks.h"
stefan6a850c32016-07-29 10:28:08 -070023#include "webrtc/base/logging.h"
Stefan Holmer60e43462016-09-07 09:58:20 +020024#include "webrtc/base/rate_statistics.h"
terelius54ce6802016-07-13 06:44:41 -070025#include "webrtc/call.h"
26#include "webrtc/common_types.h"
Stefan Holmer13181032016-07-29 14:48:54 +020027#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
terelius54ce6802016-07-13 06:44:41 -070028#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
29#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
30#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
Stefan Holmer13181032016-07-29 14:48:54 +020031#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
32#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
terelius54ce6802016-07-13 06:44:41 -070033#include "webrtc/video_receive_stream.h"
34#include "webrtc/video_send_stream.h"
35
tereliusdc35dcd2016-08-01 12:03:27 -070036namespace webrtc {
37namespace plotting {
38
terelius54ce6802016-07-13 06:44:41 -070039namespace {
40
41std::string SsrcToString(uint32_t ssrc) {
42 std::stringstream ss;
43 ss << "SSRC " << ssrc;
44 return ss.str();
45}
46
47// Checks whether an SSRC is contained in the list of desired SSRCs.
48// Note that an empty SSRC list matches every SSRC.
49bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
50 if (desired_ssrc.size() == 0)
51 return true;
52 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
53 desired_ssrc.end();
54}
55
56double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
57 // The timestamp is a fixed point representation with 6 bits for seconds
58 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
59 // time in seconds and then multiply by 1000000 to convert to microseconds.
60 static constexpr double kTimestampToMicroSec =
tereliusccbbf8d2016-08-10 07:34:28 -070061 1000000.0 / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -070062 return abs_send_time * kTimestampToMicroSec;
63}
64
65// Computes the difference |later| - |earlier| where |later| and |earlier|
66// are counters that wrap at |modulus|. The difference is chosen to have the
67// least absolute value. For example if |modulus| is 8, then the difference will
68// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
69// be in [-4, 4].
70int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
71 RTC_DCHECK_LE(1, modulus);
72 RTC_DCHECK_LT(later, modulus);
73 RTC_DCHECK_LT(earlier, modulus);
74 int64_t difference =
75 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
76 int64_t max_difference = modulus / 2;
77 int64_t min_difference = max_difference - modulus + 1;
78 if (difference > max_difference) {
79 difference -= modulus;
80 }
81 if (difference < min_difference) {
82 difference += modulus;
83 }
terelius6addf492016-08-23 17:34:07 -070084 if (difference > max_difference / 2 || difference < min_difference / 2) {
85 LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
86 << " expected to be in the range (" << min_difference / 2
87 << "," << max_difference / 2 << ") but is " << difference
88 << ". Correct unwrapping is uncertain.";
89 }
terelius54ce6802016-07-13 06:44:41 -070090 return difference;
91}
92
stefan6a850c32016-07-29 10:28:08 -070093void RegisterHeaderExtensions(
94 const std::vector<webrtc::RtpExtension>& extensions,
95 webrtc::RtpHeaderExtensionMap* extension_map) {
96 extension_map->Erase();
97 for (const webrtc::RtpExtension& extension : extensions) {
98 extension_map->Register(webrtc::StringToRtpExtensionType(extension.uri),
99 extension.id);
100 }
101}
102
tereliusdc35dcd2016-08-01 12:03:27 -0700103constexpr float kLeftMargin = 0.01f;
104constexpr float kRightMargin = 0.02f;
105constexpr float kBottomMargin = 0.02f;
106constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700107
terelius6addf492016-08-23 17:34:07 -0700108class PacketSizeBytes {
109 public:
110 using DataType = LoggedRtpPacket;
111 using ResultType = size_t;
112 size_t operator()(const LoggedRtpPacket& packet) {
113 return packet.total_length;
114 }
115};
116
117class SequenceNumberDiff {
118 public:
119 using DataType = LoggedRtpPacket;
120 using ResultType = int64_t;
121 int64_t operator()(const LoggedRtpPacket& old_packet,
122 const LoggedRtpPacket& new_packet) {
123 return WrappingDifference(new_packet.header.sequenceNumber,
124 old_packet.header.sequenceNumber, 1ul << 16);
125 }
126};
127
tereliusccbbf8d2016-08-10 07:34:28 -0700128class NetworkDelayDiff {
129 public:
130 class AbsSendTime {
131 public:
132 using DataType = LoggedRtpPacket;
133 using ResultType = double;
134 double operator()(const LoggedRtpPacket& old_packet,
135 const LoggedRtpPacket& new_packet) {
136 if (old_packet.header.extension.hasAbsoluteSendTime &&
137 new_packet.header.extension.hasAbsoluteSendTime) {
138 int64_t send_time_diff = WrappingDifference(
139 new_packet.header.extension.absoluteSendTime,
140 old_packet.header.extension.absoluteSendTime, 1ul << 24);
141 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
142 return static_cast<double>(recv_time_diff -
143 AbsSendTimeToMicroseconds(send_time_diff)) /
144 1000;
145 } else {
146 return 0;
147 }
148 }
149 };
150
151 class CaptureTime {
152 public:
153 using DataType = LoggedRtpPacket;
154 using ResultType = double;
155 double operator()(const LoggedRtpPacket& old_packet,
156 const LoggedRtpPacket& new_packet) {
157 int64_t send_time_diff = WrappingDifference(
158 new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32);
159 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
160
161 const double kVideoSampleRate = 90000;
162 // TODO(terelius): We treat all streams as video for now, even though
163 // audio might be sampled at e.g. 16kHz, because it is really difficult to
164 // figure out the true sampling rate of a stream. The effect is that the
165 // delay will be scaled incorrectly for non-video streams.
166
167 double delay_change =
168 static_cast<double>(recv_time_diff) / 1000 -
169 static_cast<double>(send_time_diff) / kVideoSampleRate * 1000;
terelius6addf492016-08-23 17:34:07 -0700170 if (delay_change < -10000 || 10000 < delay_change) {
171 LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
172 LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp
173 << ", received time " << old_packet.timestamp;
174 LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp
175 << ", received time " << new_packet.timestamp;
176 LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
177 << static_cast<double>(recv_time_diff) / 1000000 << "s";
178 LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
179 << static_cast<double>(send_time_diff) /
180 kVideoSampleRate
181 << "s";
182 }
tereliusccbbf8d2016-08-10 07:34:28 -0700183 return delay_change;
184 }
185 };
186};
187
188template <typename Extractor>
189class Accumulated {
190 public:
191 using DataType = typename Extractor::DataType;
192 using ResultType = typename Extractor::ResultType;
193 ResultType operator()(const DataType& old_packet,
194 const DataType& new_packet) {
195 sum += extract(old_packet, new_packet);
196 return sum;
197 }
198
199 private:
200 Extractor extract;
201 ResultType sum = 0;
202};
203
terelius6addf492016-08-23 17:34:07 -0700204// For each element in data, use |Extractor| to extract a y-coordinate and
205// store the result in a TimeSeries.
206template <typename Extractor>
207void Pointwise(const std::vector<typename Extractor::DataType>& data,
208 uint64_t begin_time,
209 TimeSeries* result) {
210 Extractor extract;
211 for (size_t i = 0; i < data.size(); i++) {
212 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
213 float y = extract(data[i]);
214 result->points.emplace_back(x, y);
215 }
216}
217
218// For each pair of adjacent elements in |data|, use |Extractor| to extract a
219// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
220// will be the time of the second element in the pair.
tereliusccbbf8d2016-08-10 07:34:28 -0700221template <typename Extractor>
222void Pairwise(const std::vector<typename Extractor::DataType>& data,
223 uint64_t begin_time,
224 TimeSeries* result) {
225 Extractor extract;
226 for (size_t i = 1; i < data.size(); i++) {
227 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
228 float y = extract(data[i - 1], data[i]);
229 result->points.emplace_back(x, y);
230 }
231}
232
terelius6addf492016-08-23 17:34:07 -0700233// Calculates a moving average of |data| and stores the result in a TimeSeries.
234// A data point is generated every |step| microseconds from |begin_time|
235// to |end_time|. The value of each data point is the average of the data
236// during the preceeding |window_duration_us| microseconds.
237template <typename Extractor>
238void MovingAverage(const std::vector<typename Extractor::DataType>& data,
239 uint64_t begin_time,
240 uint64_t end_time,
241 uint64_t window_duration_us,
242 uint64_t step,
243 float y_scaling,
244 webrtc::plotting::TimeSeries* result) {
245 size_t window_index_begin = 0;
246 size_t window_index_end = 0;
247 typename Extractor::ResultType sum_in_window = 0;
248 Extractor extract;
249
250 for (uint64_t t = begin_time; t < end_time + step; t += step) {
251 while (window_index_end < data.size() &&
252 data[window_index_end].timestamp < t) {
253 sum_in_window += extract(data[window_index_end]);
254 ++window_index_end;
255 }
256 while (window_index_begin < data.size() &&
257 data[window_index_begin].timestamp < t - window_duration_us) {
258 sum_in_window -= extract(data[window_index_begin]);
259 ++window_index_begin;
260 }
261 float window_duration_s = static_cast<float>(window_duration_us) / 1000000;
262 float x = static_cast<float>(t - begin_time) / 1000000;
263 float y = sum_in_window / window_duration_s * y_scaling;
264 result->points.emplace_back(x, y);
265 }
266}
267
terelius54ce6802016-07-13 06:44:41 -0700268} // namespace
269
terelius54ce6802016-07-13 06:44:41 -0700270EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log)
271 : parsed_log_(log), window_duration_(250000), step_(10000) {
272 uint64_t first_timestamp = std::numeric_limits<uint64_t>::max();
273 uint64_t last_timestamp = std::numeric_limits<uint64_t>::min();
terelius88e64e52016-07-19 01:51:06 -0700274
Stefan Holmer13181032016-07-29 14:48:54 +0200275 // Maps a stream identifier consisting of ssrc and direction
terelius88e64e52016-07-19 01:51:06 -0700276 // to the header extensions used by that stream,
277 std::map<StreamId, RtpHeaderExtensionMap> extension_maps;
278
279 PacketDirection direction;
terelius88e64e52016-07-19 01:51:06 -0700280 uint8_t header[IP_PACKET_SIZE];
281 size_t header_length;
282 size_t total_length;
283
terelius54ce6802016-07-13 06:44:41 -0700284 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
285 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
terelius88e64e52016-07-19 01:51:06 -0700286 if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT &&
287 event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT &&
288 event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT &&
terelius88c1d2b2016-08-01 05:20:33 -0700289 event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT &&
290 event_type != ParsedRtcEventLog::LOG_START &&
291 event_type != ParsedRtcEventLog::LOG_END) {
terelius88e64e52016-07-19 01:51:06 -0700292 uint64_t timestamp = parsed_log_.GetTimestamp(i);
293 first_timestamp = std::min(first_timestamp, timestamp);
294 last_timestamp = std::max(last_timestamp, timestamp);
295 }
296
297 switch (parsed_log_.GetEventType(i)) {
298 case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: {
299 VideoReceiveStream::Config config(nullptr);
300 parsed_log_.GetVideoReceiveConfig(i, &config);
Stefan Holmer13181032016-07-29 14:48:54 +0200301 StreamId stream(config.rtp.remote_ssrc, kIncomingPacket);
stefan6a850c32016-07-29 10:28:08 -0700302 RegisterHeaderExtensions(config.rtp.extensions,
303 &extension_maps[stream]);
terelius0740a202016-08-08 10:21:04 -0700304 video_ssrcs_.insert(stream);
stefan6a850c32016-07-29 10:28:08 -0700305 for (auto kv : config.rtp.rtx) {
306 StreamId rtx_stream(kv.second.ssrc, kIncomingPacket);
307 RegisterHeaderExtensions(config.rtp.extensions,
308 &extension_maps[rtx_stream]);
terelius0740a202016-08-08 10:21:04 -0700309 video_ssrcs_.insert(rtx_stream);
310 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700311 }
312 break;
313 }
314 case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: {
315 VideoSendStream::Config config(nullptr);
316 parsed_log_.GetVideoSendConfig(i, &config);
317 for (auto ssrc : config.rtp.ssrcs) {
Stefan Holmer13181032016-07-29 14:48:54 +0200318 StreamId stream(ssrc, kOutgoingPacket);
stefan6a850c32016-07-29 10:28:08 -0700319 RegisterHeaderExtensions(config.rtp.extensions,
320 &extension_maps[stream]);
terelius0740a202016-08-08 10:21:04 -0700321 video_ssrcs_.insert(stream);
stefan6a850c32016-07-29 10:28:08 -0700322 }
323 for (auto ssrc : config.rtp.rtx.ssrcs) {
terelius0740a202016-08-08 10:21:04 -0700324 StreamId rtx_stream(ssrc, kOutgoingPacket);
stefan6a850c32016-07-29 10:28:08 -0700325 RegisterHeaderExtensions(config.rtp.extensions,
terelius0740a202016-08-08 10:21:04 -0700326 &extension_maps[rtx_stream]);
327 video_ssrcs_.insert(rtx_stream);
328 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700329 }
330 break;
331 }
332 case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: {
333 AudioReceiveStream::Config config;
334 // TODO(terelius): Parse the audio configs once we have them.
335 break;
336 }
337 case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: {
338 AudioSendStream::Config config(nullptr);
339 // TODO(terelius): Parse the audio configs once we have them.
340 break;
341 }
342 case ParsedRtcEventLog::RTP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200343 MediaType media_type;
terelius88e64e52016-07-19 01:51:06 -0700344 parsed_log_.GetRtpHeader(i, &direction, &media_type, header,
345 &header_length, &total_length);
346 // Parse header to get SSRC.
347 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
348 RTPHeader parsed_header;
349 rtp_parser.Parse(&parsed_header);
Stefan Holmer13181032016-07-29 14:48:54 +0200350 StreamId stream(parsed_header.ssrc, direction);
terelius88e64e52016-07-19 01:51:06 -0700351 // Look up the extension_map and parse it again to get the extensions.
352 if (extension_maps.count(stream) == 1) {
353 RtpHeaderExtensionMap* extension_map = &extension_maps[stream];
354 rtp_parser.Parse(&parsed_header, extension_map);
355 }
356 uint64_t timestamp = parsed_log_.GetTimestamp(i);
357 rtp_packets_[stream].push_back(
Stefan Holmer13181032016-07-29 14:48:54 +0200358 LoggedRtpPacket(timestamp, parsed_header, total_length));
terelius88e64e52016-07-19 01:51:06 -0700359 break;
360 }
361 case ParsedRtcEventLog::RTCP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200362 uint8_t packet[IP_PACKET_SIZE];
363 MediaType media_type;
364 parsed_log_.GetRtcpPacket(i, &direction, &media_type, packet,
365 &total_length);
366
367 RtpUtility::RtpHeaderParser rtp_parser(packet, total_length);
368 RTPHeader parsed_header;
369 RTC_CHECK(rtp_parser.ParseRtcp(&parsed_header));
370 uint32_t ssrc = parsed_header.ssrc;
371
372 RTCPUtility::RTCPParserV2 rtcp_parser(packet, total_length, true);
373 RTC_CHECK(rtcp_parser.IsValid());
374
375 RTCPUtility::RTCPPacketTypes packet_type = rtcp_parser.Begin();
376 while (packet_type != RTCPUtility::RTCPPacketTypes::kInvalid) {
377 switch (packet_type) {
378 case RTCPUtility::RTCPPacketTypes::kTransportFeedback: {
379 // Currently feedback is logged twice, both for audio and video.
380 // Only act on one of them.
381 if (media_type == MediaType::VIDEO) {
382 std::unique_ptr<rtcp::RtcpPacket> rtcp_packet(
383 rtcp_parser.ReleaseRtcpPacket());
384 StreamId stream(ssrc, direction);
385 uint64_t timestamp = parsed_log_.GetTimestamp(i);
386 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
387 timestamp, kRtcpTransportFeedback, std::move(rtcp_packet)));
388 }
389 break;
390 }
391 default:
392 break;
393 }
394 rtcp_parser.Iterate();
395 packet_type = rtcp_parser.PacketType();
396 }
terelius88e64e52016-07-19 01:51:06 -0700397 break;
398 }
399 case ParsedRtcEventLog::LOG_START: {
400 break;
401 }
402 case ParsedRtcEventLog::LOG_END: {
403 break;
404 }
405 case ParsedRtcEventLog::BWE_PACKET_LOSS_EVENT: {
terelius8058e582016-07-25 01:32:41 -0700406 BwePacketLossEvent bwe_update;
407 bwe_update.timestamp = parsed_log_.GetTimestamp(i);
408 parsed_log_.GetBwePacketLossEvent(i, &bwe_update.new_bitrate,
409 &bwe_update.fraction_loss,
410 &bwe_update.expected_packets);
411 bwe_loss_updates_.push_back(bwe_update);
terelius88e64e52016-07-19 01:51:06 -0700412 break;
413 }
414 case ParsedRtcEventLog::BWE_PACKET_DELAY_EVENT: {
415 break;
416 }
417 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: {
418 break;
419 }
420 case ParsedRtcEventLog::UNKNOWN_EVENT: {
421 break;
422 }
423 }
terelius54ce6802016-07-13 06:44:41 -0700424 }
terelius88e64e52016-07-19 01:51:06 -0700425
terelius54ce6802016-07-13 06:44:41 -0700426 if (last_timestamp < first_timestamp) {
427 // No useful events in the log.
428 first_timestamp = last_timestamp = 0;
429 }
430 begin_time_ = first_timestamp;
431 end_time_ = last_timestamp;
tereliusdc35dcd2016-08-01 12:03:27 -0700432 call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000;
terelius54ce6802016-07-13 06:44:41 -0700433}
434
Stefan Holmer13181032016-07-29 14:48:54 +0200435class BitrateObserver : public CongestionController::Observer,
436 public RemoteBitrateObserver {
437 public:
438 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
439
440 void OnNetworkChanged(uint32_t bitrate_bps,
441 uint8_t fraction_loss,
442 int64_t rtt_ms) override {
443 last_bitrate_bps_ = bitrate_bps;
444 bitrate_updated_ = true;
445 }
446
447 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
448 uint32_t bitrate) override {}
449
450 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
451 bool GetAndResetBitrateUpdated() {
452 bool bitrate_updated = bitrate_updated_;
453 bitrate_updated_ = false;
454 return bitrate_updated;
455 }
456
457 private:
458 uint32_t last_bitrate_bps_;
459 bool bitrate_updated_;
460};
461
terelius0740a202016-08-08 10:21:04 -0700462bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) {
463 return rtx_ssrcs_.count(stream_id) == 1;
464}
465
466bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) {
467 return video_ssrcs_.count(stream_id) == 1;
468}
469
470bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) {
471 return audio_ssrcs_.count(stream_id) == 1;
472}
473
terelius54ce6802016-07-13 06:44:41 -0700474void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
475 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700476 for (auto& kv : rtp_packets_) {
477 StreamId stream_id = kv.first;
478 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
479 // Filter on direction and SSRC.
480 if (stream_id.GetDirection() != desired_direction ||
481 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
482 continue;
terelius54ce6802016-07-13 06:44:41 -0700483 }
terelius54ce6802016-07-13 06:44:41 -0700484
terelius6addf492016-08-23 17:34:07 -0700485 TimeSeries time_series;
486 time_series.label = SsrcToString(stream_id.GetSsrc());
487 time_series.style = BAR_GRAPH;
488 Pointwise<PacketSizeBytes>(packet_stream, begin_time_, &time_series);
489 plot->series_list_.push_back(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700490 }
491
tereliusdc35dcd2016-08-01 12:03:27 -0700492 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
493 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
494 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700495 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700496 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700497 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700498 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700499 }
500}
501
philipelccd74892016-09-05 02:46:25 -0700502template <typename T>
503void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
504 PacketDirection desired_direction,
505 Plot* plot,
506 const std::map<StreamId, std::vector<T>>& packets,
507 const std::string& label_prefix) {
508 for (auto& kv : packets) {
509 StreamId stream_id = kv.first;
510 const std::vector<T>& packet_stream = kv.second;
511 // Filter on direction and SSRC.
512 if (stream_id.GetDirection() != desired_direction ||
513 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
514 continue;
515 }
516
517 TimeSeries time_series;
518 time_series.label = label_prefix + " " + SsrcToString(stream_id.GetSsrc());
519 time_series.style = LINE_GRAPH;
520
521 for (size_t i = 0; i < packet_stream.size(); i++) {
522 float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) /
523 1000000;
524 time_series.points.emplace_back(x, i);
525 time_series.points.emplace_back(x, i + 1);
526 }
527
528 plot->series_list_.push_back(std::move(time_series));
529 }
530}
531
532void EventLogAnalyzer::CreateAccumulatedPacketsGraph(
533 PacketDirection desired_direction,
534 Plot* plot) {
535 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_,
536 "RTP");
537 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_,
538 "RTCP");
539
540 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
541 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
542 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
543 plot->SetTitle("Accumulated Incoming RTP/RTCP packets");
544 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
545 plot->SetTitle("Accumulated Outgoing RTP/RTCP packets");
546 }
547}
548
terelius54ce6802016-07-13 06:44:41 -0700549// For each SSRC, plot the time between the consecutive playouts.
550void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
551 std::map<uint32_t, TimeSeries> time_series;
552 std::map<uint32_t, uint64_t> last_playout;
553
554 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700555
556 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
557 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
558 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
559 parsed_log_.GetAudioPlayout(i, &ssrc);
560 uint64_t timestamp = parsed_log_.GetTimestamp(i);
561 if (MatchingSsrc(ssrc, desired_ssrc_)) {
562 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
563 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
564 if (time_series[ssrc].points.size() == 0) {
565 // There were no previusly logged playout for this SSRC.
566 // Generate a point, but place it on the x-axis.
567 y = 0;
568 }
terelius54ce6802016-07-13 06:44:41 -0700569 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
570 last_playout[ssrc] = timestamp;
571 }
572 }
573 }
574
575 // Set labels and put in graph.
576 for (auto& kv : time_series) {
577 kv.second.label = SsrcToString(kv.first);
578 kv.second.style = BAR_GRAPH;
tereliusdc35dcd2016-08-01 12:03:27 -0700579 plot->series_list_.push_back(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700580 }
581
tereliusdc35dcd2016-08-01 12:03:27 -0700582 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
583 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
584 kTopMargin);
585 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700586}
587
588// For each SSRC, plot the time between the consecutive playouts.
589void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700590 for (auto& kv : rtp_packets_) {
591 StreamId stream_id = kv.first;
592 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
593 // Filter on direction and SSRC.
594 if (stream_id.GetDirection() != kIncomingPacket ||
595 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
596 continue;
terelius54ce6802016-07-13 06:44:41 -0700597 }
terelius54ce6802016-07-13 06:44:41 -0700598
terelius6addf492016-08-23 17:34:07 -0700599 TimeSeries time_series;
600 time_series.label = SsrcToString(stream_id.GetSsrc());
601 time_series.style = BAR_GRAPH;
602 Pairwise<SequenceNumberDiff>(packet_stream, begin_time_, &time_series);
603 plot->series_list_.push_back(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700604 }
605
tereliusdc35dcd2016-08-01 12:03:27 -0700606 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
607 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
608 kTopMargin);
609 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700610}
611
612void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700613 for (auto& kv : rtp_packets_) {
614 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700615 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
616 uint32_t ssrc = stream_id.GetSsrc();
terelius88e64e52016-07-19 01:51:06 -0700617 // Filter on direction and SSRC.
618 if (stream_id.GetDirection() != kIncomingPacket ||
tereliusccbbf8d2016-08-10 07:34:28 -0700619 !MatchingSsrc(ssrc, desired_ssrc_) || IsAudioSsrc(stream_id) ||
620 !IsVideoSsrc(stream_id) || IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700621 continue;
622 }
terelius54ce6802016-07-13 06:44:41 -0700623
tereliusccbbf8d2016-08-10 07:34:28 -0700624 TimeSeries capture_time_data;
625 capture_time_data.label = SsrcToString(ssrc) + " capture-time";
626 capture_time_data.style = BAR_GRAPH;
627 Pairwise<NetworkDelayDiff::CaptureTime>(packet_stream, begin_time_,
628 &capture_time_data);
629 plot->series_list_.push_back(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700630
tereliusccbbf8d2016-08-10 07:34:28 -0700631 TimeSeries send_time_data;
632 send_time_data.label = SsrcToString(ssrc) + " abs-send-time";
633 send_time_data.style = BAR_GRAPH;
634 Pairwise<NetworkDelayDiff::AbsSendTime>(packet_stream, begin_time_,
635 &send_time_data);
636 plot->series_list_.push_back(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700637 }
638
tereliusdc35dcd2016-08-01 12:03:27 -0700639 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
640 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
641 kTopMargin);
642 plot->SetTitle("Network latency change between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700643}
644
645void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700646 for (auto& kv : rtp_packets_) {
647 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700648 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
649 uint32_t ssrc = stream_id.GetSsrc();
terelius88e64e52016-07-19 01:51:06 -0700650 // Filter on direction and SSRC.
651 if (stream_id.GetDirection() != kIncomingPacket ||
tereliusccbbf8d2016-08-10 07:34:28 -0700652 !MatchingSsrc(ssrc, desired_ssrc_) || IsAudioSsrc(stream_id) ||
653 !IsVideoSsrc(stream_id) || IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700654 continue;
655 }
terelius54ce6802016-07-13 06:44:41 -0700656
tereliusccbbf8d2016-08-10 07:34:28 -0700657 TimeSeries capture_time_data;
658 capture_time_data.label = SsrcToString(ssrc) + " capture-time";
659 capture_time_data.style = LINE_GRAPH;
660 Pairwise<Accumulated<NetworkDelayDiff::CaptureTime>>(
661 packet_stream, begin_time_, &capture_time_data);
662 plot->series_list_.push_back(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700663
tereliusccbbf8d2016-08-10 07:34:28 -0700664 TimeSeries send_time_data;
665 send_time_data.label = SsrcToString(ssrc) + " abs-send-time";
666 send_time_data.style = LINE_GRAPH;
667 Pairwise<Accumulated<NetworkDelayDiff::AbsSendTime>>(
668 packet_stream, begin_time_, &send_time_data);
669 plot->series_list_.push_back(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700670 }
671
tereliusdc35dcd2016-08-01 12:03:27 -0700672 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
673 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
674 kTopMargin);
675 plot->SetTitle("Accumulated network latency change");
terelius54ce6802016-07-13 06:44:41 -0700676}
677
tereliusf736d232016-08-04 10:00:11 -0700678// Plot the fraction of packets lost (as perceived by the loss-based BWE).
679void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
680 plot->series_list_.push_back(TimeSeries());
681 for (auto& bwe_update : bwe_loss_updates_) {
682 float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
683 float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100;
684 plot->series_list_.back().points.emplace_back(x, y);
685 }
686 plot->series_list_.back().label = "Fraction lost";
687 plot->series_list_.back().style = LINE_DOT_GRAPH;
688
689 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
690 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
691 kTopMargin);
692 plot->SetTitle("Reported packet loss");
693}
694
terelius54ce6802016-07-13 06:44:41 -0700695// Plot the total bandwidth used by all RTP streams.
696void EventLogAnalyzer::CreateTotalBitrateGraph(
697 PacketDirection desired_direction,
698 Plot* plot) {
699 struct TimestampSize {
700 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
701 uint64_t timestamp;
702 size_t size;
703 };
704 std::vector<TimestampSize> packets;
705
706 PacketDirection direction;
707 size_t total_length;
708
709 // Extract timestamps and sizes for the relevant packets.
710 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
711 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
712 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
713 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, nullptr,
714 &total_length);
715 if (direction == desired_direction) {
716 uint64_t timestamp = parsed_log_.GetTimestamp(i);
717 packets.push_back(TimestampSize(timestamp, total_length));
718 }
719 }
720 }
721
722 size_t window_index_begin = 0;
723 size_t window_index_end = 0;
724 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700725
726 // Calculate a moving average of the bitrate and store in a TimeSeries.
tereliusdc35dcd2016-08-01 12:03:27 -0700727 plot->series_list_.push_back(TimeSeries());
terelius54ce6802016-07-13 06:44:41 -0700728 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
729 while (window_index_end < packets.size() &&
730 packets[window_index_end].timestamp < time) {
731 bytes_in_window += packets[window_index_end].size;
terelius6addf492016-08-23 17:34:07 -0700732 ++window_index_end;
terelius54ce6802016-07-13 06:44:41 -0700733 }
734 while (window_index_begin < packets.size() &&
735 packets[window_index_begin].timestamp < time - window_duration_) {
736 RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window);
737 bytes_in_window -= packets[window_index_begin].size;
terelius6addf492016-08-23 17:34:07 -0700738 ++window_index_begin;
terelius54ce6802016-07-13 06:44:41 -0700739 }
740 float window_duration_in_seconds =
741 static_cast<float>(window_duration_) / 1000000;
742 float x = static_cast<float>(time - begin_time_) / 1000000;
743 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
tereliusdc35dcd2016-08-01 12:03:27 -0700744 plot->series_list_.back().points.push_back(TimeSeriesPoint(x, y));
terelius54ce6802016-07-13 06:44:41 -0700745 }
746
747 // Set labels.
748 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700749 plot->series_list_.back().label = "Incoming bitrate";
terelius54ce6802016-07-13 06:44:41 -0700750 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700751 plot->series_list_.back().label = "Outgoing bitrate";
terelius54ce6802016-07-13 06:44:41 -0700752 }
tereliusdc35dcd2016-08-01 12:03:27 -0700753 plot->series_list_.back().style = LINE_GRAPH;
terelius54ce6802016-07-13 06:44:41 -0700754
terelius8058e582016-07-25 01:32:41 -0700755 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
756 if (desired_direction == kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700757 plot->series_list_.push_back(TimeSeries());
terelius8058e582016-07-25 01:32:41 -0700758 for (auto& bwe_update : bwe_loss_updates_) {
759 float x =
760 static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
761 float y = static_cast<float>(bwe_update.new_bitrate) / 1000;
tereliusdc35dcd2016-08-01 12:03:27 -0700762 plot->series_list_.back().points.emplace_back(x, y);
terelius8058e582016-07-25 01:32:41 -0700763 }
tereliusdc35dcd2016-08-01 12:03:27 -0700764 plot->series_list_.back().label = "Loss-based estimate";
765 plot->series_list_.back().style = LINE_GRAPH;
terelius8058e582016-07-25 01:32:41 -0700766 }
tereliusdc35dcd2016-08-01 12:03:27 -0700767 plot->series_list_.back().style = LINE_GRAPH;
768 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
769 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700770 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700771 plot->SetTitle("Incoming RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -0700772 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700773 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -0700774 }
775}
776
777// For each SSRC, plot the bandwidth used by that stream.
778void EventLogAnalyzer::CreateStreamBitrateGraph(
779 PacketDirection desired_direction,
780 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700781 for (auto& kv : rtp_packets_) {
782 StreamId stream_id = kv.first;
783 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
784 // Filter on direction and SSRC.
785 if (stream_id.GetDirection() != desired_direction ||
786 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
787 continue;
terelius54ce6802016-07-13 06:44:41 -0700788 }
789
terelius6addf492016-08-23 17:34:07 -0700790 TimeSeries time_series;
791 time_series.label = SsrcToString(stream_id.GetSsrc());
792 time_series.style = LINE_GRAPH;
793 double bytes_to_kilobits = 8.0 / 1000;
794 MovingAverage<PacketSizeBytes>(packet_stream, begin_time_, end_time_,
795 window_duration_, step_, bytes_to_kilobits,
796 &time_series);
797 plot->series_list_.push_back(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700798 }
799
tereliusdc35dcd2016-08-01 12:03:27 -0700800 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
801 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700802 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700803 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -0700804 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700805 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -0700806 }
807}
808
tereliuse34c19c2016-08-15 08:47:14 -0700809void EventLogAnalyzer::CreateBweSimulationGraph(Plot* plot) {
Stefan Holmer13181032016-07-29 14:48:54 +0200810 std::map<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
811 std::map<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
812
813 for (const auto& kv : rtp_packets_) {
814 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
815 for (const LoggedRtpPacket& rtp_packet : kv.second)
816 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
817 }
818 }
819
820 for (const auto& kv : rtcp_packets_) {
821 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
822 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
823 incoming_rtcp.insert(
824 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
825 }
826 }
827
828 SimulatedClock clock(0);
829 BitrateObserver observer;
830 RtcEventLogNullImpl null_event_log;
831 CongestionController cc(&clock, &observer, &observer, &null_event_log);
832 // TODO(holmer): Log the call config and use that here instead.
833 static const uint32_t kDefaultStartBitrateBps = 300000;
834 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
835
836 TimeSeries time_series;
tereliuse34c19c2016-08-15 08:47:14 -0700837 time_series.label = "Delay-based estimate";
Stefan Holmer13181032016-07-29 14:48:54 +0200838 time_series.style = LINE_DOT_GRAPH;
Stefan Holmer60e43462016-09-07 09:58:20 +0200839 TimeSeries acked_time_series;
840 acked_time_series.label = "Acked bitrate";
841 acked_time_series.style = LINE_DOT_GRAPH;
Stefan Holmer13181032016-07-29 14:48:54 +0200842
843 auto rtp_iterator = outgoing_rtp.begin();
844 auto rtcp_iterator = incoming_rtcp.begin();
845
846 auto NextRtpTime = [&]() {
847 if (rtp_iterator != outgoing_rtp.end())
848 return static_cast<int64_t>(rtp_iterator->first);
849 return std::numeric_limits<int64_t>::max();
850 };
851
852 auto NextRtcpTime = [&]() {
853 if (rtcp_iterator != incoming_rtcp.end())
854 return static_cast<int64_t>(rtcp_iterator->first);
855 return std::numeric_limits<int64_t>::max();
856 };
857
858 auto NextProcessTime = [&]() {
859 if (rtcp_iterator != incoming_rtcp.end() ||
860 rtp_iterator != outgoing_rtp.end()) {
861 return clock.TimeInMicroseconds() +
862 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
863 }
864 return std::numeric_limits<int64_t>::max();
865 };
866
Stefan Holmer60e43462016-09-07 09:58:20 +0200867 RateStatistics acked_bitrate(1000, 8000);
868
Stefan Holmer13181032016-07-29 14:48:54 +0200869 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
870 while (time_us != std::numeric_limits<int64_t>::max()) {
871 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
872 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -0700873 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +0200874 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
875 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +0200876 TransportFeedbackObserver* observer = cc.GetTransportFeedbackObserver();
877 observer->OnTransportFeedback(*static_cast<rtcp::TransportFeedback*>(
878 rtcp.packet.get()));
879 std::vector<PacketInfo> feedback =
880 observer->GetTransportFeedbackVector();
881 rtc::Optional<uint32_t> bitrate_bps;
882 if (!feedback.empty()) {
883 for (const PacketInfo& packet : feedback)
884 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
885 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
886 }
887 uint32_t y = 0;
888 if (bitrate_bps)
889 y = *bitrate_bps / 1000;
890 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
891 1000000;
892 acked_time_series.points.emplace_back(x, y);
Stefan Holmer13181032016-07-29 14:48:54 +0200893 }
894 ++rtcp_iterator;
895 }
896 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -0700897 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Stefan Holmer13181032016-07-29 14:48:54 +0200898 const LoggedRtpPacket& rtp = *rtp_iterator->second;
899 if (rtp.header.extension.hasTransportSequenceNumber) {
900 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
901 cc.GetTransportFeedbackObserver()->AddPacket(
stefana93d5ac2016-08-17 02:14:32 -0700902 rtp.header.extension.transportSequenceNumber, rtp.total_length,
903 PacketInfo::kNotAProbe);
Stefan Holmer13181032016-07-29 14:48:54 +0200904 rtc::SentPacket sent_packet(
905 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
906 cc.OnSentPacket(sent_packet);
907 }
908 ++rtp_iterator;
909 }
stefanc3de0332016-08-02 07:22:17 -0700910 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
911 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +0200912 cc.Process();
stefanc3de0332016-08-02 07:22:17 -0700913 }
Stefan Holmer13181032016-07-29 14:48:54 +0200914 if (observer.GetAndResetBitrateUpdated()) {
915 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer13181032016-07-29 14:48:54 +0200916 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
917 1000000;
918 time_series.points.emplace_back(x, y);
919 }
920 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
921 }
922 // Add the data set to the plot.
tereliusdc35dcd2016-08-01 12:03:27 -0700923 plot->series_list_.push_back(std::move(time_series));
Stefan Holmer60e43462016-09-07 09:58:20 +0200924 plot->series_list_.push_back(std::move(acked_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +0200925
tereliusdc35dcd2016-08-01 12:03:27 -0700926 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
927 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
928 plot->SetTitle("Simulated BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +0200929}
930
tereliuse34c19c2016-08-15 08:47:14 -0700931void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanc3de0332016-08-02 07:22:17 -0700932 std::map<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
933 std::map<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
934
935 for (const auto& kv : rtp_packets_) {
936 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
937 for (const LoggedRtpPacket& rtp_packet : kv.second)
938 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
939 }
940 }
941
942 for (const auto& kv : rtcp_packets_) {
943 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
944 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
945 incoming_rtcp.insert(
946 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
947 }
948 }
949
950 SimulatedClock clock(0);
951 TransportFeedbackAdapter feedback_adapter(nullptr, &clock);
952
953 TimeSeries time_series;
954 time_series.label = "Network Delay Change";
955 time_series.style = LINE_DOT_GRAPH;
956 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
957
958 auto rtp_iterator = outgoing_rtp.begin();
959 auto rtcp_iterator = incoming_rtcp.begin();
960
961 auto NextRtpTime = [&]() {
962 if (rtp_iterator != outgoing_rtp.end())
963 return static_cast<int64_t>(rtp_iterator->first);
964 return std::numeric_limits<int64_t>::max();
965 };
966
967 auto NextRtcpTime = [&]() {
968 if (rtcp_iterator != incoming_rtcp.end())
969 return static_cast<int64_t>(rtcp_iterator->first);
970 return std::numeric_limits<int64_t>::max();
971 };
972
973 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
974 while (time_us != std::numeric_limits<int64_t>::max()) {
975 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
976 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
977 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
978 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
979 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +0200980 feedback_adapter.OnTransportFeedback(
981 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
stefanc3de0332016-08-02 07:22:17 -0700982 std::vector<PacketInfo> feedback =
Stefan Holmer60e43462016-09-07 09:58:20 +0200983 feedback_adapter.GetTransportFeedbackVector();
stefanc3de0332016-08-02 07:22:17 -0700984 for (const PacketInfo& packet : feedback) {
985 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
986 float x =
987 static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
988 1000000;
989 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
990 time_series.points.emplace_back(x, y);
991 }
992 }
993 ++rtcp_iterator;
994 }
995 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
996 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
997 const LoggedRtpPacket& rtp = *rtp_iterator->second;
998 if (rtp.header.extension.hasTransportSequenceNumber) {
999 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
1000 feedback_adapter.AddPacket(rtp.header.extension.transportSequenceNumber,
1001 rtp.total_length, 0);
1002 feedback_adapter.OnSentPacket(
1003 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1004 }
1005 ++rtp_iterator;
1006 }
1007 time_us = std::min(NextRtpTime(), NextRtcpTime());
1008 }
1009 // We assume that the base network delay (w/o queues) is the min delay
1010 // observed during the call.
1011 for (TimeSeriesPoint& point : time_series.points)
1012 point.y -= estimated_base_delay_ms;
1013 // Add the data set to the plot.
1014 plot->series_list_.push_back(std::move(time_series));
1015
1016 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1017 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1018 plot->SetTitle("Network Delay Change.");
1019}
terelius54ce6802016-07-13 06:44:41 -07001020} // namespace plotting
1021} // namespace webrtc