blob: 1db7672b9cb01451ffc4d0b54293eede97c82463 [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
20#include "webrtc/audio_receive_stream.h"
21#include "webrtc/audio_send_stream.h"
22#include "webrtc/base/checks.h"
stefan6a850c32016-07-29 10:28:08 -070023#include "webrtc/base/logging.h"
terelius54ce6802016-07-13 06:44:41 -070024#include "webrtc/call.h"
25#include "webrtc/common_types.h"
Stefan Holmer13181032016-07-29 14:48:54 +020026#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
terelius54ce6802016-07-13 06:44:41 -070027#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
28#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
29#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
Stefan Holmer13181032016-07-29 14:48:54 +020030#include "webrtc/modules/rtp_rtcp/source/rtcp_utility.h"
31#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
terelius54ce6802016-07-13 06:44:41 -070032#include "webrtc/video_receive_stream.h"
33#include "webrtc/video_send_stream.h"
34
tereliusdc35dcd2016-08-01 12:03:27 -070035namespace webrtc {
36namespace plotting {
37
terelius54ce6802016-07-13 06:44:41 -070038namespace {
39
40std::string SsrcToString(uint32_t ssrc) {
41 std::stringstream ss;
42 ss << "SSRC " << ssrc;
43 return ss.str();
44}
45
46// Checks whether an SSRC is contained in the list of desired SSRCs.
47// Note that an empty SSRC list matches every SSRC.
48bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
49 if (desired_ssrc.size() == 0)
50 return true;
51 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
52 desired_ssrc.end();
53}
54
55double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
56 // The timestamp is a fixed point representation with 6 bits for seconds
57 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
58 // time in seconds and then multiply by 1000000 to convert to microseconds.
59 static constexpr double kTimestampToMicroSec =
tereliusccbbf8d2016-08-10 07:34:28 -070060 1000000.0 / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -070061 return abs_send_time * kTimestampToMicroSec;
62}
63
64// Computes the difference |later| - |earlier| where |later| and |earlier|
65// are counters that wrap at |modulus|. The difference is chosen to have the
66// least absolute value. For example if |modulus| is 8, then the difference will
67// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
68// be in [-4, 4].
69int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
70 RTC_DCHECK_LE(1, modulus);
71 RTC_DCHECK_LT(later, modulus);
72 RTC_DCHECK_LT(earlier, modulus);
73 int64_t difference =
74 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
75 int64_t max_difference = modulus / 2;
76 int64_t min_difference = max_difference - modulus + 1;
77 if (difference > max_difference) {
78 difference -= modulus;
79 }
80 if (difference < min_difference) {
81 difference += modulus;
82 }
83 return difference;
84}
85
stefan6a850c32016-07-29 10:28:08 -070086void RegisterHeaderExtensions(
87 const std::vector<webrtc::RtpExtension>& extensions,
88 webrtc::RtpHeaderExtensionMap* extension_map) {
89 extension_map->Erase();
90 for (const webrtc::RtpExtension& extension : extensions) {
91 extension_map->Register(webrtc::StringToRtpExtensionType(extension.uri),
92 extension.id);
93 }
94}
95
tereliusdc35dcd2016-08-01 12:03:27 -070096constexpr float kLeftMargin = 0.01f;
97constexpr float kRightMargin = 0.02f;
98constexpr float kBottomMargin = 0.02f;
99constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700100
tereliusccbbf8d2016-08-10 07:34:28 -0700101class NetworkDelayDiff {
102 public:
103 class AbsSendTime {
104 public:
105 using DataType = LoggedRtpPacket;
106 using ResultType = double;
107 double operator()(const LoggedRtpPacket& old_packet,
108 const LoggedRtpPacket& new_packet) {
109 if (old_packet.header.extension.hasAbsoluteSendTime &&
110 new_packet.header.extension.hasAbsoluteSendTime) {
111 int64_t send_time_diff = WrappingDifference(
112 new_packet.header.extension.absoluteSendTime,
113 old_packet.header.extension.absoluteSendTime, 1ul << 24);
114 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
115 return static_cast<double>(recv_time_diff -
116 AbsSendTimeToMicroseconds(send_time_diff)) /
117 1000;
118 } else {
119 return 0;
120 }
121 }
122 };
123
124 class CaptureTime {
125 public:
126 using DataType = LoggedRtpPacket;
127 using ResultType = double;
128 double operator()(const LoggedRtpPacket& old_packet,
129 const LoggedRtpPacket& new_packet) {
130 int64_t send_time_diff = WrappingDifference(
131 new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32);
132 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
133
134 const double kVideoSampleRate = 90000;
135 // TODO(terelius): We treat all streams as video for now, even though
136 // audio might be sampled at e.g. 16kHz, because it is really difficult to
137 // figure out the true sampling rate of a stream. The effect is that the
138 // delay will be scaled incorrectly for non-video streams.
139
140 double delay_change =
141 static_cast<double>(recv_time_diff) / 1000 -
142 static_cast<double>(send_time_diff) / kVideoSampleRate * 1000;
143 return delay_change;
144 }
145 };
146};
147
148template <typename Extractor>
149class Accumulated {
150 public:
151 using DataType = typename Extractor::DataType;
152 using ResultType = typename Extractor::ResultType;
153 ResultType operator()(const DataType& old_packet,
154 const DataType& new_packet) {
155 sum += extract(old_packet, new_packet);
156 return sum;
157 }
158
159 private:
160 Extractor extract;
161 ResultType sum = 0;
162};
163
164template <typename Extractor>
165void Pairwise(const std::vector<typename Extractor::DataType>& data,
166 uint64_t begin_time,
167 TimeSeries* result) {
168 Extractor extract;
169 for (size_t i = 1; i < data.size(); i++) {
170 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
171 float y = extract(data[i - 1], data[i]);
172 result->points.emplace_back(x, y);
173 }
174}
175
terelius54ce6802016-07-13 06:44:41 -0700176} // namespace
177
terelius54ce6802016-07-13 06:44:41 -0700178EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log)
179 : parsed_log_(log), window_duration_(250000), step_(10000) {
180 uint64_t first_timestamp = std::numeric_limits<uint64_t>::max();
181 uint64_t last_timestamp = std::numeric_limits<uint64_t>::min();
terelius88e64e52016-07-19 01:51:06 -0700182
Stefan Holmer13181032016-07-29 14:48:54 +0200183 // Maps a stream identifier consisting of ssrc and direction
terelius88e64e52016-07-19 01:51:06 -0700184 // to the header extensions used by that stream,
185 std::map<StreamId, RtpHeaderExtensionMap> extension_maps;
186
187 PacketDirection direction;
terelius88e64e52016-07-19 01:51:06 -0700188 uint8_t header[IP_PACKET_SIZE];
189 size_t header_length;
190 size_t total_length;
191
terelius54ce6802016-07-13 06:44:41 -0700192 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
193 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
terelius88e64e52016-07-19 01:51:06 -0700194 if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT &&
195 event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT &&
196 event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT &&
terelius88c1d2b2016-08-01 05:20:33 -0700197 event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT &&
198 event_type != ParsedRtcEventLog::LOG_START &&
199 event_type != ParsedRtcEventLog::LOG_END) {
terelius88e64e52016-07-19 01:51:06 -0700200 uint64_t timestamp = parsed_log_.GetTimestamp(i);
201 first_timestamp = std::min(first_timestamp, timestamp);
202 last_timestamp = std::max(last_timestamp, timestamp);
203 }
204
205 switch (parsed_log_.GetEventType(i)) {
206 case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: {
207 VideoReceiveStream::Config config(nullptr);
208 parsed_log_.GetVideoReceiveConfig(i, &config);
Stefan Holmer13181032016-07-29 14:48:54 +0200209 StreamId stream(config.rtp.remote_ssrc, kIncomingPacket);
stefan6a850c32016-07-29 10:28:08 -0700210 RegisterHeaderExtensions(config.rtp.extensions,
211 &extension_maps[stream]);
terelius0740a202016-08-08 10:21:04 -0700212 video_ssrcs_.insert(stream);
stefan6a850c32016-07-29 10:28:08 -0700213 for (auto kv : config.rtp.rtx) {
214 StreamId rtx_stream(kv.second.ssrc, kIncomingPacket);
215 RegisterHeaderExtensions(config.rtp.extensions,
216 &extension_maps[rtx_stream]);
terelius0740a202016-08-08 10:21:04 -0700217 video_ssrcs_.insert(rtx_stream);
218 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700219 }
220 break;
221 }
222 case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: {
223 VideoSendStream::Config config(nullptr);
224 parsed_log_.GetVideoSendConfig(i, &config);
225 for (auto ssrc : config.rtp.ssrcs) {
Stefan Holmer13181032016-07-29 14:48:54 +0200226 StreamId stream(ssrc, kOutgoingPacket);
stefan6a850c32016-07-29 10:28:08 -0700227 RegisterHeaderExtensions(config.rtp.extensions,
228 &extension_maps[stream]);
terelius0740a202016-08-08 10:21:04 -0700229 video_ssrcs_.insert(stream);
stefan6a850c32016-07-29 10:28:08 -0700230 }
231 for (auto ssrc : config.rtp.rtx.ssrcs) {
terelius0740a202016-08-08 10:21:04 -0700232 StreamId rtx_stream(ssrc, kOutgoingPacket);
stefan6a850c32016-07-29 10:28:08 -0700233 RegisterHeaderExtensions(config.rtp.extensions,
terelius0740a202016-08-08 10:21:04 -0700234 &extension_maps[rtx_stream]);
235 video_ssrcs_.insert(rtx_stream);
236 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700237 }
238 break;
239 }
240 case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: {
241 AudioReceiveStream::Config config;
242 // TODO(terelius): Parse the audio configs once we have them.
243 break;
244 }
245 case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: {
246 AudioSendStream::Config config(nullptr);
247 // TODO(terelius): Parse the audio configs once we have them.
248 break;
249 }
250 case ParsedRtcEventLog::RTP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200251 MediaType media_type;
terelius88e64e52016-07-19 01:51:06 -0700252 parsed_log_.GetRtpHeader(i, &direction, &media_type, header,
253 &header_length, &total_length);
254 // Parse header to get SSRC.
255 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
256 RTPHeader parsed_header;
257 rtp_parser.Parse(&parsed_header);
Stefan Holmer13181032016-07-29 14:48:54 +0200258 StreamId stream(parsed_header.ssrc, direction);
terelius88e64e52016-07-19 01:51:06 -0700259 // Look up the extension_map and parse it again to get the extensions.
260 if (extension_maps.count(stream) == 1) {
261 RtpHeaderExtensionMap* extension_map = &extension_maps[stream];
262 rtp_parser.Parse(&parsed_header, extension_map);
263 }
264 uint64_t timestamp = parsed_log_.GetTimestamp(i);
265 rtp_packets_[stream].push_back(
Stefan Holmer13181032016-07-29 14:48:54 +0200266 LoggedRtpPacket(timestamp, parsed_header, total_length));
terelius88e64e52016-07-19 01:51:06 -0700267 break;
268 }
269 case ParsedRtcEventLog::RTCP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200270 uint8_t packet[IP_PACKET_SIZE];
271 MediaType media_type;
272 parsed_log_.GetRtcpPacket(i, &direction, &media_type, packet,
273 &total_length);
274
275 RtpUtility::RtpHeaderParser rtp_parser(packet, total_length);
276 RTPHeader parsed_header;
277 RTC_CHECK(rtp_parser.ParseRtcp(&parsed_header));
278 uint32_t ssrc = parsed_header.ssrc;
279
280 RTCPUtility::RTCPParserV2 rtcp_parser(packet, total_length, true);
281 RTC_CHECK(rtcp_parser.IsValid());
282
283 RTCPUtility::RTCPPacketTypes packet_type = rtcp_parser.Begin();
284 while (packet_type != RTCPUtility::RTCPPacketTypes::kInvalid) {
285 switch (packet_type) {
286 case RTCPUtility::RTCPPacketTypes::kTransportFeedback: {
287 // Currently feedback is logged twice, both for audio and video.
288 // Only act on one of them.
289 if (media_type == MediaType::VIDEO) {
290 std::unique_ptr<rtcp::RtcpPacket> rtcp_packet(
291 rtcp_parser.ReleaseRtcpPacket());
292 StreamId stream(ssrc, direction);
293 uint64_t timestamp = parsed_log_.GetTimestamp(i);
294 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
295 timestamp, kRtcpTransportFeedback, std::move(rtcp_packet)));
296 }
297 break;
298 }
299 default:
300 break;
301 }
302 rtcp_parser.Iterate();
303 packet_type = rtcp_parser.PacketType();
304 }
terelius88e64e52016-07-19 01:51:06 -0700305 break;
306 }
307 case ParsedRtcEventLog::LOG_START: {
308 break;
309 }
310 case ParsedRtcEventLog::LOG_END: {
311 break;
312 }
313 case ParsedRtcEventLog::BWE_PACKET_LOSS_EVENT: {
terelius8058e582016-07-25 01:32:41 -0700314 BwePacketLossEvent bwe_update;
315 bwe_update.timestamp = parsed_log_.GetTimestamp(i);
316 parsed_log_.GetBwePacketLossEvent(i, &bwe_update.new_bitrate,
317 &bwe_update.fraction_loss,
318 &bwe_update.expected_packets);
319 bwe_loss_updates_.push_back(bwe_update);
terelius88e64e52016-07-19 01:51:06 -0700320 break;
321 }
322 case ParsedRtcEventLog::BWE_PACKET_DELAY_EVENT: {
323 break;
324 }
325 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: {
326 break;
327 }
328 case ParsedRtcEventLog::UNKNOWN_EVENT: {
329 break;
330 }
331 }
terelius54ce6802016-07-13 06:44:41 -0700332 }
terelius88e64e52016-07-19 01:51:06 -0700333
terelius54ce6802016-07-13 06:44:41 -0700334 if (last_timestamp < first_timestamp) {
335 // No useful events in the log.
336 first_timestamp = last_timestamp = 0;
337 }
338 begin_time_ = first_timestamp;
339 end_time_ = last_timestamp;
tereliusdc35dcd2016-08-01 12:03:27 -0700340 call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000;
terelius54ce6802016-07-13 06:44:41 -0700341}
342
Stefan Holmer13181032016-07-29 14:48:54 +0200343class BitrateObserver : public CongestionController::Observer,
344 public RemoteBitrateObserver {
345 public:
346 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
347
348 void OnNetworkChanged(uint32_t bitrate_bps,
349 uint8_t fraction_loss,
350 int64_t rtt_ms) override {
351 last_bitrate_bps_ = bitrate_bps;
352 bitrate_updated_ = true;
353 }
354
355 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
356 uint32_t bitrate) override {}
357
358 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
359 bool GetAndResetBitrateUpdated() {
360 bool bitrate_updated = bitrate_updated_;
361 bitrate_updated_ = false;
362 return bitrate_updated;
363 }
364
365 private:
366 uint32_t last_bitrate_bps_;
367 bool bitrate_updated_;
368};
369
terelius0740a202016-08-08 10:21:04 -0700370bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) {
371 return rtx_ssrcs_.count(stream_id) == 1;
372}
373
374bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) {
375 return video_ssrcs_.count(stream_id) == 1;
376}
377
378bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) {
379 return audio_ssrcs_.count(stream_id) == 1;
380}
381
terelius54ce6802016-07-13 06:44:41 -0700382void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
383 Plot* plot) {
384 std::map<uint32_t, TimeSeries> time_series;
385
386 PacketDirection direction;
387 MediaType media_type;
388 uint8_t header[IP_PACKET_SIZE];
389 size_t header_length, total_length;
terelius54ce6802016-07-13 06:44:41 -0700390
391 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
392 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
393 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
394 parsed_log_.GetRtpHeader(i, &direction, &media_type, header,
395 &header_length, &total_length);
396 if (direction == desired_direction) {
397 // Parse header to get SSRC.
398 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
399 RTPHeader parsed_header;
400 rtp_parser.Parse(&parsed_header);
401 // Filter on SSRC.
402 if (MatchingSsrc(parsed_header.ssrc, desired_ssrc_)) {
403 uint64_t timestamp = parsed_log_.GetTimestamp(i);
404 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
405 float y = total_length;
terelius54ce6802016-07-13 06:44:41 -0700406 time_series[parsed_header.ssrc].points.push_back(
407 TimeSeriesPoint(x, y));
408 }
409 }
410 }
411 }
412
413 // Set labels and put in graph.
414 for (auto& kv : time_series) {
415 kv.second.label = SsrcToString(kv.first);
416 kv.second.style = BAR_GRAPH;
tereliusdc35dcd2016-08-01 12:03:27 -0700417 plot->series_list_.push_back(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700418 }
419
tereliusdc35dcd2016-08-01 12:03:27 -0700420 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
421 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
422 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700423 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700424 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700425 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700426 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700427 }
428}
429
430// For each SSRC, plot the time between the consecutive playouts.
431void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
432 std::map<uint32_t, TimeSeries> time_series;
433 std::map<uint32_t, uint64_t> last_playout;
434
435 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700436
437 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
438 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
439 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
440 parsed_log_.GetAudioPlayout(i, &ssrc);
441 uint64_t timestamp = parsed_log_.GetTimestamp(i);
442 if (MatchingSsrc(ssrc, desired_ssrc_)) {
443 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
444 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
445 if (time_series[ssrc].points.size() == 0) {
446 // There were no previusly logged playout for this SSRC.
447 // Generate a point, but place it on the x-axis.
448 y = 0;
449 }
terelius54ce6802016-07-13 06:44:41 -0700450 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
451 last_playout[ssrc] = timestamp;
452 }
453 }
454 }
455
456 // Set labels and put in graph.
457 for (auto& kv : time_series) {
458 kv.second.label = SsrcToString(kv.first);
459 kv.second.style = BAR_GRAPH;
tereliusdc35dcd2016-08-01 12:03:27 -0700460 plot->series_list_.push_back(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700461 }
462
tereliusdc35dcd2016-08-01 12:03:27 -0700463 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
464 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
465 kTopMargin);
466 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700467}
468
469// For each SSRC, plot the time between the consecutive playouts.
470void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
471 std::map<uint32_t, TimeSeries> time_series;
472 std::map<uint32_t, uint16_t> last_seqno;
473
474 PacketDirection direction;
475 MediaType media_type;
476 uint8_t header[IP_PACKET_SIZE];
477 size_t header_length, total_length;
478
terelius54ce6802016-07-13 06:44:41 -0700479 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
480 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
481 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
482 parsed_log_.GetRtpHeader(i, &direction, &media_type, header,
483 &header_length, &total_length);
484 uint64_t timestamp = parsed_log_.GetTimestamp(i);
485 if (direction == PacketDirection::kIncomingPacket) {
486 // Parse header to get SSRC.
487 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
488 RTPHeader parsed_header;
489 rtp_parser.Parse(&parsed_header);
490 // Filter on SSRC.
491 if (MatchingSsrc(parsed_header.ssrc, desired_ssrc_)) {
492 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
493 int y = WrappingDifference(parsed_header.sequenceNumber,
494 last_seqno[parsed_header.ssrc], 1ul << 16);
495 if (time_series[parsed_header.ssrc].points.size() == 0) {
496 // There were no previusly logged playout for this SSRC.
497 // Generate a point, but place it on the x-axis.
498 y = 0;
499 }
terelius54ce6802016-07-13 06:44:41 -0700500 time_series[parsed_header.ssrc].points.push_back(
501 TimeSeriesPoint(x, y));
502 last_seqno[parsed_header.ssrc] = parsed_header.sequenceNumber;
503 }
504 }
505 }
506 }
507
508 // Set labels and put in graph.
509 for (auto& kv : time_series) {
510 kv.second.label = SsrcToString(kv.first);
511 kv.second.style = BAR_GRAPH;
tereliusdc35dcd2016-08-01 12:03:27 -0700512 plot->series_list_.push_back(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700513 }
514
tereliusdc35dcd2016-08-01 12:03:27 -0700515 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
516 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
517 kTopMargin);
518 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700519}
520
521void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700522 for (auto& kv : rtp_packets_) {
523 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700524 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
525 uint32_t ssrc = stream_id.GetSsrc();
terelius88e64e52016-07-19 01:51:06 -0700526 // Filter on direction and SSRC.
527 if (stream_id.GetDirection() != kIncomingPacket ||
tereliusccbbf8d2016-08-10 07:34:28 -0700528 !MatchingSsrc(ssrc, desired_ssrc_) || IsAudioSsrc(stream_id) ||
529 !IsVideoSsrc(stream_id) || IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700530 continue;
531 }
terelius54ce6802016-07-13 06:44:41 -0700532
tereliusccbbf8d2016-08-10 07:34:28 -0700533 TimeSeries capture_time_data;
534 capture_time_data.label = SsrcToString(ssrc) + " capture-time";
535 capture_time_data.style = BAR_GRAPH;
536 Pairwise<NetworkDelayDiff::CaptureTime>(packet_stream, begin_time_,
537 &capture_time_data);
538 plot->series_list_.push_back(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700539
tereliusccbbf8d2016-08-10 07:34:28 -0700540 TimeSeries send_time_data;
541 send_time_data.label = SsrcToString(ssrc) + " abs-send-time";
542 send_time_data.style = BAR_GRAPH;
543 Pairwise<NetworkDelayDiff::AbsSendTime>(packet_stream, begin_time_,
544 &send_time_data);
545 plot->series_list_.push_back(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700546 }
547
tereliusdc35dcd2016-08-01 12:03:27 -0700548 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
549 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
550 kTopMargin);
551 plot->SetTitle("Network latency change between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700552}
553
554void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700555 for (auto& kv : rtp_packets_) {
556 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700557 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
558 uint32_t ssrc = stream_id.GetSsrc();
terelius88e64e52016-07-19 01:51:06 -0700559 // Filter on direction and SSRC.
560 if (stream_id.GetDirection() != kIncomingPacket ||
tereliusccbbf8d2016-08-10 07:34:28 -0700561 !MatchingSsrc(ssrc, desired_ssrc_) || IsAudioSsrc(stream_id) ||
562 !IsVideoSsrc(stream_id) || IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700563 continue;
564 }
terelius54ce6802016-07-13 06:44:41 -0700565
tereliusccbbf8d2016-08-10 07:34:28 -0700566 TimeSeries capture_time_data;
567 capture_time_data.label = SsrcToString(ssrc) + " capture-time";
568 capture_time_data.style = LINE_GRAPH;
569 Pairwise<Accumulated<NetworkDelayDiff::CaptureTime>>(
570 packet_stream, begin_time_, &capture_time_data);
571 plot->series_list_.push_back(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700572
tereliusccbbf8d2016-08-10 07:34:28 -0700573 TimeSeries send_time_data;
574 send_time_data.label = SsrcToString(ssrc) + " abs-send-time";
575 send_time_data.style = LINE_GRAPH;
576 Pairwise<Accumulated<NetworkDelayDiff::AbsSendTime>>(
577 packet_stream, begin_time_, &send_time_data);
578 plot->series_list_.push_back(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700579 }
580
tereliusdc35dcd2016-08-01 12:03:27 -0700581 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
582 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
583 kTopMargin);
584 plot->SetTitle("Accumulated network latency change");
terelius54ce6802016-07-13 06:44:41 -0700585}
586
tereliusf736d232016-08-04 10:00:11 -0700587// Plot the fraction of packets lost (as perceived by the loss-based BWE).
588void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
589 plot->series_list_.push_back(TimeSeries());
590 for (auto& bwe_update : bwe_loss_updates_) {
591 float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
592 float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100;
593 plot->series_list_.back().points.emplace_back(x, y);
594 }
595 plot->series_list_.back().label = "Fraction lost";
596 plot->series_list_.back().style = LINE_DOT_GRAPH;
597
598 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
599 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
600 kTopMargin);
601 plot->SetTitle("Reported packet loss");
602}
603
terelius54ce6802016-07-13 06:44:41 -0700604// Plot the total bandwidth used by all RTP streams.
605void EventLogAnalyzer::CreateTotalBitrateGraph(
606 PacketDirection desired_direction,
607 Plot* plot) {
608 struct TimestampSize {
609 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
610 uint64_t timestamp;
611 size_t size;
612 };
613 std::vector<TimestampSize> packets;
614
615 PacketDirection direction;
616 size_t total_length;
617
618 // Extract timestamps and sizes for the relevant packets.
619 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
620 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
621 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
622 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, nullptr,
623 &total_length);
624 if (direction == desired_direction) {
625 uint64_t timestamp = parsed_log_.GetTimestamp(i);
626 packets.push_back(TimestampSize(timestamp, total_length));
627 }
628 }
629 }
630
631 size_t window_index_begin = 0;
632 size_t window_index_end = 0;
633 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700634
635 // Calculate a moving average of the bitrate and store in a TimeSeries.
tereliusdc35dcd2016-08-01 12:03:27 -0700636 plot->series_list_.push_back(TimeSeries());
terelius54ce6802016-07-13 06:44:41 -0700637 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
638 while (window_index_end < packets.size() &&
639 packets[window_index_end].timestamp < time) {
640 bytes_in_window += packets[window_index_end].size;
641 window_index_end++;
642 }
643 while (window_index_begin < packets.size() &&
644 packets[window_index_begin].timestamp < time - window_duration_) {
645 RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window);
646 bytes_in_window -= packets[window_index_begin].size;
647 window_index_begin++;
648 }
649 float window_duration_in_seconds =
650 static_cast<float>(window_duration_) / 1000000;
651 float x = static_cast<float>(time - begin_time_) / 1000000;
652 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
tereliusdc35dcd2016-08-01 12:03:27 -0700653 plot->series_list_.back().points.push_back(TimeSeriesPoint(x, y));
terelius54ce6802016-07-13 06:44:41 -0700654 }
655
656 // Set labels.
657 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700658 plot->series_list_.back().label = "Incoming bitrate";
terelius54ce6802016-07-13 06:44:41 -0700659 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700660 plot->series_list_.back().label = "Outgoing bitrate";
terelius54ce6802016-07-13 06:44:41 -0700661 }
tereliusdc35dcd2016-08-01 12:03:27 -0700662 plot->series_list_.back().style = LINE_GRAPH;
terelius54ce6802016-07-13 06:44:41 -0700663
terelius8058e582016-07-25 01:32:41 -0700664 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
665 if (desired_direction == kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700666 plot->series_list_.push_back(TimeSeries());
terelius8058e582016-07-25 01:32:41 -0700667 for (auto& bwe_update : bwe_loss_updates_) {
668 float x =
669 static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
670 float y = static_cast<float>(bwe_update.new_bitrate) / 1000;
tereliusdc35dcd2016-08-01 12:03:27 -0700671 plot->series_list_.back().points.emplace_back(x, y);
terelius8058e582016-07-25 01:32:41 -0700672 }
tereliusdc35dcd2016-08-01 12:03:27 -0700673 plot->series_list_.back().label = "Loss-based estimate";
674 plot->series_list_.back().style = LINE_GRAPH;
terelius8058e582016-07-25 01:32:41 -0700675 }
tereliusdc35dcd2016-08-01 12:03:27 -0700676 plot->series_list_.back().style = LINE_GRAPH;
677 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
678 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700679 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700680 plot->SetTitle("Incoming RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -0700681 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700682 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -0700683 }
684}
685
686// For each SSRC, plot the bandwidth used by that stream.
687void EventLogAnalyzer::CreateStreamBitrateGraph(
688 PacketDirection desired_direction,
689 Plot* plot) {
690 struct TimestampSize {
691 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
692 uint64_t timestamp;
693 size_t size;
694 };
terelius88e64e52016-07-19 01:51:06 -0700695 std::map<uint32_t, std::vector<TimestampSize>> packets;
terelius54ce6802016-07-13 06:44:41 -0700696
697 PacketDirection direction;
698 MediaType media_type;
699 uint8_t header[IP_PACKET_SIZE];
700 size_t header_length, total_length;
701
702 // Extract timestamps and sizes for the relevant packets.
703 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
704 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
705 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
706 parsed_log_.GetRtpHeader(i, &direction, &media_type, header,
707 &header_length, &total_length);
708 if (direction == desired_direction) {
709 // Parse header to get SSRC.
710 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
711 RTPHeader parsed_header;
712 rtp_parser.Parse(&parsed_header);
713 // Filter on SSRC.
714 if (MatchingSsrc(parsed_header.ssrc, desired_ssrc_)) {
715 uint64_t timestamp = parsed_log_.GetTimestamp(i);
716 packets[parsed_header.ssrc].push_back(
717 TimestampSize(timestamp, total_length));
718 }
719 }
720 }
721 }
722
terelius54ce6802016-07-13 06:44:41 -0700723 for (auto& kv : packets) {
724 size_t window_index_begin = 0;
725 size_t window_index_end = 0;
726 size_t bytes_in_window = 0;
727
728 // Calculate a moving average of the bitrate and store in a TimeSeries.
tereliusdc35dcd2016-08-01 12:03:27 -0700729 plot->series_list_.push_back(TimeSeries());
terelius54ce6802016-07-13 06:44:41 -0700730 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
731 while (window_index_end < kv.second.size() &&
732 kv.second[window_index_end].timestamp < time) {
733 bytes_in_window += kv.second[window_index_end].size;
734 window_index_end++;
735 }
736 while (window_index_begin < kv.second.size() &&
737 kv.second[window_index_begin].timestamp <
738 time - window_duration_) {
739 RTC_DCHECK_LE(kv.second[window_index_begin].size, bytes_in_window);
740 bytes_in_window -= kv.second[window_index_begin].size;
741 window_index_begin++;
742 }
743 float window_duration_in_seconds =
744 static_cast<float>(window_duration_) / 1000000;
745 float x = static_cast<float>(time - begin_time_) / 1000000;
746 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
tereliusdc35dcd2016-08-01 12:03:27 -0700747 plot->series_list_.back().points.push_back(TimeSeriesPoint(x, y));
terelius54ce6802016-07-13 06:44:41 -0700748 }
749
750 // Set labels.
tereliusdc35dcd2016-08-01 12:03:27 -0700751 plot->series_list_.back().label = SsrcToString(kv.first);
752 plot->series_list_.back().style = LINE_GRAPH;
terelius54ce6802016-07-13 06:44:41 -0700753 }
754
tereliusdc35dcd2016-08-01 12:03:27 -0700755 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
756 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700757 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700758 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -0700759 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700760 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -0700761 }
762}
763
tereliuse34c19c2016-08-15 08:47:14 -0700764void EventLogAnalyzer::CreateBweSimulationGraph(Plot* plot) {
Stefan Holmer13181032016-07-29 14:48:54 +0200765 std::map<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
766 std::map<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
767
768 for (const auto& kv : rtp_packets_) {
769 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
770 for (const LoggedRtpPacket& rtp_packet : kv.second)
771 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
772 }
773 }
774
775 for (const auto& kv : rtcp_packets_) {
776 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
777 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
778 incoming_rtcp.insert(
779 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
780 }
781 }
782
783 SimulatedClock clock(0);
784 BitrateObserver observer;
785 RtcEventLogNullImpl null_event_log;
786 CongestionController cc(&clock, &observer, &observer, &null_event_log);
787 // TODO(holmer): Log the call config and use that here instead.
788 static const uint32_t kDefaultStartBitrateBps = 300000;
789 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
790
791 TimeSeries time_series;
tereliuse34c19c2016-08-15 08:47:14 -0700792 time_series.label = "Delay-based estimate";
Stefan Holmer13181032016-07-29 14:48:54 +0200793 time_series.style = LINE_DOT_GRAPH;
Stefan Holmer13181032016-07-29 14:48:54 +0200794
795 auto rtp_iterator = outgoing_rtp.begin();
796 auto rtcp_iterator = incoming_rtcp.begin();
797
798 auto NextRtpTime = [&]() {
799 if (rtp_iterator != outgoing_rtp.end())
800 return static_cast<int64_t>(rtp_iterator->first);
801 return std::numeric_limits<int64_t>::max();
802 };
803
804 auto NextRtcpTime = [&]() {
805 if (rtcp_iterator != incoming_rtcp.end())
806 return static_cast<int64_t>(rtcp_iterator->first);
807 return std::numeric_limits<int64_t>::max();
808 };
809
810 auto NextProcessTime = [&]() {
811 if (rtcp_iterator != incoming_rtcp.end() ||
812 rtp_iterator != outgoing_rtp.end()) {
813 return clock.TimeInMicroseconds() +
814 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
815 }
816 return std::numeric_limits<int64_t>::max();
817 };
818
819 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
820 while (time_us != std::numeric_limits<int64_t>::max()) {
821 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
822 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -0700823 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +0200824 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
825 if (rtcp.type == kRtcpTransportFeedback) {
826 cc.GetTransportFeedbackObserver()->OnTransportFeedback(
827 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
828 }
829 ++rtcp_iterator;
830 }
831 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -0700832 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Stefan Holmer13181032016-07-29 14:48:54 +0200833 const LoggedRtpPacket& rtp = *rtp_iterator->second;
834 if (rtp.header.extension.hasTransportSequenceNumber) {
835 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
836 cc.GetTransportFeedbackObserver()->AddPacket(
stefana93d5ac2016-08-17 02:14:32 -0700837 rtp.header.extension.transportSequenceNumber, rtp.total_length,
838 PacketInfo::kNotAProbe);
Stefan Holmer13181032016-07-29 14:48:54 +0200839 rtc::SentPacket sent_packet(
840 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
841 cc.OnSentPacket(sent_packet);
842 }
843 ++rtp_iterator;
844 }
stefanc3de0332016-08-02 07:22:17 -0700845 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
846 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +0200847 cc.Process();
stefanc3de0332016-08-02 07:22:17 -0700848 }
Stefan Holmer13181032016-07-29 14:48:54 +0200849 if (observer.GetAndResetBitrateUpdated()) {
850 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer13181032016-07-29 14:48:54 +0200851 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
852 1000000;
853 time_series.points.emplace_back(x, y);
854 }
855 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
856 }
857 // Add the data set to the plot.
tereliusdc35dcd2016-08-01 12:03:27 -0700858 plot->series_list_.push_back(std::move(time_series));
Stefan Holmer13181032016-07-29 14:48:54 +0200859
tereliusdc35dcd2016-08-01 12:03:27 -0700860 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
861 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
862 plot->SetTitle("Simulated BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +0200863}
864
tereliuse34c19c2016-08-15 08:47:14 -0700865void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanc3de0332016-08-02 07:22:17 -0700866 std::map<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
867 std::map<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
868
869 for (const auto& kv : rtp_packets_) {
870 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
871 for (const LoggedRtpPacket& rtp_packet : kv.second)
872 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
873 }
874 }
875
876 for (const auto& kv : rtcp_packets_) {
877 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
878 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
879 incoming_rtcp.insert(
880 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
881 }
882 }
883
884 SimulatedClock clock(0);
885 TransportFeedbackAdapter feedback_adapter(nullptr, &clock);
886
887 TimeSeries time_series;
888 time_series.label = "Network Delay Change";
889 time_series.style = LINE_DOT_GRAPH;
890 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
891
892 auto rtp_iterator = outgoing_rtp.begin();
893 auto rtcp_iterator = incoming_rtcp.begin();
894
895 auto NextRtpTime = [&]() {
896 if (rtp_iterator != outgoing_rtp.end())
897 return static_cast<int64_t>(rtp_iterator->first);
898 return std::numeric_limits<int64_t>::max();
899 };
900
901 auto NextRtcpTime = [&]() {
902 if (rtcp_iterator != incoming_rtcp.end())
903 return static_cast<int64_t>(rtcp_iterator->first);
904 return std::numeric_limits<int64_t>::max();
905 };
906
907 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
908 while (time_us != std::numeric_limits<int64_t>::max()) {
909 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
910 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
911 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
912 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
913 if (rtcp.type == kRtcpTransportFeedback) {
914 std::vector<PacketInfo> feedback =
915 feedback_adapter.GetPacketFeedbackVector(
916 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
917 for (const PacketInfo& packet : feedback) {
918 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
919 float x =
920 static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
921 1000000;
922 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
923 time_series.points.emplace_back(x, y);
924 }
925 }
926 ++rtcp_iterator;
927 }
928 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
929 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
930 const LoggedRtpPacket& rtp = *rtp_iterator->second;
931 if (rtp.header.extension.hasTransportSequenceNumber) {
932 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
933 feedback_adapter.AddPacket(rtp.header.extension.transportSequenceNumber,
934 rtp.total_length, 0);
935 feedback_adapter.OnSentPacket(
936 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
937 }
938 ++rtp_iterator;
939 }
940 time_us = std::min(NextRtpTime(), NextRtcpTime());
941 }
942 // We assume that the base network delay (w/o queues) is the min delay
943 // observed during the call.
944 for (TimeSeriesPoint& point : time_series.points)
945 point.y -= estimated_base_delay_ms;
946 // Add the data set to the plot.
947 plot->series_list_.push_back(std::move(time_series));
948
949 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
950 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
951 plot->SetTitle("Network Delay Change.");
952}
terelius54ce6802016-07-13 06:44:41 -0700953} // namespace plotting
954} // namespace webrtc