blob: 2f8b7ed02f30247b7e252e76a52c94576363f7dd [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 }
438 case ParsedRtcEventLog::BWE_PACKET_LOSS_EVENT: {
terelius8058e582016-07-25 01:32:41 -0700439 BwePacketLossEvent bwe_update;
440 bwe_update.timestamp = parsed_log_.GetTimestamp(i);
441 parsed_log_.GetBwePacketLossEvent(i, &bwe_update.new_bitrate,
442 &bwe_update.fraction_loss,
443 &bwe_update.expected_packets);
444 bwe_loss_updates_.push_back(bwe_update);
terelius88e64e52016-07-19 01:51:06 -0700445 break;
446 }
minyue4b7c9522017-01-24 04:54:59 -0800447 case ParsedRtcEventLog::AUDIO_NETWORK_ADAPTATION_EVENT: {
448 break;
449 }
terelius88e64e52016-07-19 01:51:06 -0700450 case ParsedRtcEventLog::BWE_PACKET_DELAY_EVENT: {
451 break;
452 }
453 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: {
454 break;
455 }
456 case ParsedRtcEventLog::UNKNOWN_EVENT: {
457 break;
458 }
459 }
terelius54ce6802016-07-13 06:44:41 -0700460 }
terelius88e64e52016-07-19 01:51:06 -0700461
terelius54ce6802016-07-13 06:44:41 -0700462 if (last_timestamp < first_timestamp) {
463 // No useful events in the log.
464 first_timestamp = last_timestamp = 0;
465 }
466 begin_time_ = first_timestamp;
467 end_time_ = last_timestamp;
tereliusdc35dcd2016-08-01 12:03:27 -0700468 call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000;
terelius54ce6802016-07-13 06:44:41 -0700469}
470
Stefan Holmer13181032016-07-29 14:48:54 +0200471class BitrateObserver : public CongestionController::Observer,
472 public RemoteBitrateObserver {
473 public:
474 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
475
minyue78b4d562016-11-30 04:47:39 -0800476 // TODO(minyue): remove this when old OnNetworkChanged is deprecated. See
477 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6796
478 using CongestionController::Observer::OnNetworkChanged;
479
Stefan Holmer13181032016-07-29 14:48:54 +0200480 void OnNetworkChanged(uint32_t bitrate_bps,
481 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800482 int64_t rtt_ms,
483 int64_t probing_interval_ms) override {
Stefan Holmer13181032016-07-29 14:48:54 +0200484 last_bitrate_bps_ = bitrate_bps;
485 bitrate_updated_ = true;
486 }
487
488 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
489 uint32_t bitrate) override {}
490
491 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
492 bool GetAndResetBitrateUpdated() {
493 bool bitrate_updated = bitrate_updated_;
494 bitrate_updated_ = false;
495 return bitrate_updated;
496 }
497
498 private:
499 uint32_t last_bitrate_bps_;
500 bool bitrate_updated_;
501};
502
Stefan Holmer99f8e082016-09-09 13:37:50 +0200503bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700504 return rtx_ssrcs_.count(stream_id) == 1;
505}
506
Stefan Holmer99f8e082016-09-09 13:37:50 +0200507bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700508 return video_ssrcs_.count(stream_id) == 1;
509}
510
Stefan Holmer99f8e082016-09-09 13:37:50 +0200511bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700512 return audio_ssrcs_.count(stream_id) == 1;
513}
514
Stefan Holmer99f8e082016-09-09 13:37:50 +0200515std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const {
516 std::stringstream name;
517 if (IsAudioSsrc(stream_id)) {
518 name << "Audio ";
519 } else if (IsVideoSsrc(stream_id)) {
520 name << "Video ";
521 } else {
522 name << "Unknown ";
523 }
524 if (IsRtxSsrc(stream_id))
525 name << "RTX ";
ivocaac9d6f2016-09-22 07:01:47 -0700526 if (stream_id.GetDirection() == kIncomingPacket) {
527 name << "(In) ";
528 } else {
529 name << "(Out) ";
530 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200531 name << SsrcToString(stream_id.GetSsrc());
532 return name.str();
533}
534
terelius54ce6802016-07-13 06:44:41 -0700535void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
536 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700537 for (auto& kv : rtp_packets_) {
538 StreamId stream_id = kv.first;
539 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
540 // Filter on direction and SSRC.
541 if (stream_id.GetDirection() != desired_direction ||
542 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
543 continue;
terelius54ce6802016-07-13 06:44:41 -0700544 }
terelius54ce6802016-07-13 06:44:41 -0700545
terelius6addf492016-08-23 17:34:07 -0700546 TimeSeries time_series;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200547 time_series.label = GetStreamName(stream_id);
terelius6addf492016-08-23 17:34:07 -0700548 time_series.style = BAR_GRAPH;
549 Pointwise<PacketSizeBytes>(packet_stream, begin_time_, &time_series);
550 plot->series_list_.push_back(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700551 }
552
tereliusdc35dcd2016-08-01 12:03:27 -0700553 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
554 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
555 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700556 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700557 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700558 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700559 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700560 }
561}
562
philipelccd74892016-09-05 02:46:25 -0700563template <typename T>
564void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
565 PacketDirection desired_direction,
566 Plot* plot,
567 const std::map<StreamId, std::vector<T>>& packets,
568 const std::string& label_prefix) {
569 for (auto& kv : packets) {
570 StreamId stream_id = kv.first;
571 const std::vector<T>& packet_stream = kv.second;
572 // Filter on direction and SSRC.
573 if (stream_id.GetDirection() != desired_direction ||
574 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
575 continue;
576 }
577
578 TimeSeries time_series;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200579 time_series.label = label_prefix + " " + GetStreamName(stream_id);
terelius77f05802017-02-01 06:34:53 -0800580 time_series.style = LINE_STEP_GRAPH;
philipelccd74892016-09-05 02:46:25 -0700581
582 for (size_t i = 0; i < packet_stream.size(); i++) {
583 float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) /
584 1000000;
philipelccd74892016-09-05 02:46:25 -0700585 time_series.points.emplace_back(x, i + 1);
586 }
587
588 plot->series_list_.push_back(std::move(time_series));
589 }
590}
591
592void EventLogAnalyzer::CreateAccumulatedPacketsGraph(
593 PacketDirection desired_direction,
594 Plot* plot) {
595 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_,
596 "RTP");
597 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_,
598 "RTCP");
599
600 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
601 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
602 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
603 plot->SetTitle("Accumulated Incoming RTP/RTCP packets");
604 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
605 plot->SetTitle("Accumulated Outgoing RTP/RTCP packets");
606 }
607}
608
terelius54ce6802016-07-13 06:44:41 -0700609// For each SSRC, plot the time between the consecutive playouts.
610void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
611 std::map<uint32_t, TimeSeries> time_series;
612 std::map<uint32_t, uint64_t> last_playout;
613
614 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700615
616 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
617 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
618 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
619 parsed_log_.GetAudioPlayout(i, &ssrc);
620 uint64_t timestamp = parsed_log_.GetTimestamp(i);
621 if (MatchingSsrc(ssrc, desired_ssrc_)) {
622 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
623 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
624 if (time_series[ssrc].points.size() == 0) {
625 // There were no previusly logged playout for this SSRC.
626 // Generate a point, but place it on the x-axis.
627 y = 0;
628 }
terelius54ce6802016-07-13 06:44:41 -0700629 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
630 last_playout[ssrc] = timestamp;
631 }
632 }
633 }
634
635 // Set labels and put in graph.
636 for (auto& kv : time_series) {
637 kv.second.label = SsrcToString(kv.first);
638 kv.second.style = BAR_GRAPH;
tereliusdc35dcd2016-08-01 12:03:27 -0700639 plot->series_list_.push_back(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700640 }
641
tereliusdc35dcd2016-08-01 12:03:27 -0700642 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
643 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
644 kTopMargin);
645 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700646}
647
ivocaac9d6f2016-09-22 07:01:47 -0700648// For audio SSRCs, plot the audio level.
649void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) {
650 std::map<StreamId, TimeSeries> time_series;
651
652 for (auto& kv : rtp_packets_) {
653 StreamId stream_id = kv.first;
654 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
655 // TODO(ivoc): When audio send/receive configs are stored in the event
656 // log, a check should be added here to only process audio
657 // streams. Tracking bug: webrtc:6399
658 for (auto& packet : packet_stream) {
659 if (packet.header.extension.hasAudioLevel) {
660 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
661 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
662 // Here we convert it to dBov.
663 float y = static_cast<float>(-packet.header.extension.audioLevel);
664 time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y));
665 }
666 }
667 }
668
669 for (auto& series : time_series) {
670 series.second.label = GetStreamName(series.first);
671 series.second.style = LINE_GRAPH;
672 plot->series_list_.push_back(std::move(series.second));
673 }
674
675 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
ivocbf676632016-11-24 08:30:34 -0800676 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin,
ivocaac9d6f2016-09-22 07:01:47 -0700677 kTopMargin);
678 plot->SetTitle("Audio level");
679}
680
terelius54ce6802016-07-13 06:44:41 -0700681// For each SSRC, plot the time between the consecutive playouts.
682void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700683 for (auto& kv : rtp_packets_) {
684 StreamId stream_id = kv.first;
685 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
686 // Filter on direction and SSRC.
687 if (stream_id.GetDirection() != kIncomingPacket ||
688 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
689 continue;
terelius54ce6802016-07-13 06:44:41 -0700690 }
terelius54ce6802016-07-13 06:44:41 -0700691
terelius6addf492016-08-23 17:34:07 -0700692 TimeSeries time_series;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200693 time_series.label = GetStreamName(stream_id);
terelius6addf492016-08-23 17:34:07 -0700694 time_series.style = BAR_GRAPH;
695 Pairwise<SequenceNumberDiff>(packet_stream, begin_time_, &time_series);
696 plot->series_list_.push_back(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700697 }
698
tereliusdc35dcd2016-08-01 12:03:27 -0700699 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
700 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
701 kTopMargin);
702 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700703}
704
Stefan Holmer99f8e082016-09-09 13:37:50 +0200705void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
706 for (auto& kv : rtp_packets_) {
707 StreamId stream_id = kv.first;
708 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
709 // Filter on direction and SSRC.
710 if (stream_id.GetDirection() != kIncomingPacket ||
terelius4c9b4af2017-01-30 08:44:51 -0800711 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
712 packet_stream.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200713 continue;
714 }
715
716 TimeSeries time_series;
717 time_series.label = GetStreamName(stream_id);
718 time_series.style = LINE_DOT_GRAPH;
719 const uint64_t kWindowUs = 1000000;
terelius4c9b4af2017-01-30 08:44:51 -0800720 const uint64_t kStep = 1000000;
721 SequenceNumberUnwrapper unwrapper_;
722 SequenceNumberUnwrapper prior_unwrapper_;
723 size_t window_index_begin = 0;
724 size_t window_index_end = 0;
725 int64_t highest_seq_number =
726 unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
727 int64_t highest_prior_seq_number =
728 prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
729
730 for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) {
731 while (window_index_end < packet_stream.size() &&
732 packet_stream[window_index_end].timestamp < t) {
733 int64_t sequence_number = unwrapper_.Unwrap(
734 packet_stream[window_index_end].header.sequenceNumber);
735 highest_seq_number = std::max(highest_seq_number, sequence_number);
736 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200737 }
terelius4c9b4af2017-01-30 08:44:51 -0800738 while (window_index_begin < packet_stream.size() &&
739 packet_stream[window_index_begin].timestamp < t - kWindowUs) {
740 int64_t sequence_number = prior_unwrapper_.Unwrap(
741 packet_stream[window_index_begin].header.sequenceNumber);
742 highest_prior_seq_number =
743 std::max(highest_prior_seq_number, sequence_number);
744 ++window_index_begin;
745 }
746 float x = static_cast<float>(t - begin_time_) / 1000000;
747 int64_t expected_packets = highest_seq_number - highest_prior_seq_number;
748 if (expected_packets > 0) {
749 int64_t received_packets = window_index_end - window_index_begin;
750 int64_t lost_packets = expected_packets - received_packets;
751 float y = static_cast<float>(lost_packets) / expected_packets * 100;
752 time_series.points.emplace_back(x, y);
753 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200754 }
755 plot->series_list_.push_back(std::move(time_series));
756 }
757
758 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
759 plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin,
760 kTopMargin);
761 plot->SetTitle("Estimated incoming loss rate");
762}
763
terelius54ce6802016-07-13 06:44:41 -0700764void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700765 for (auto& kv : rtp_packets_) {
766 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700767 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700768 // Filter on direction and SSRC.
769 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200770 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
771 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
772 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700773 continue;
774 }
terelius54ce6802016-07-13 06:44:41 -0700775
tereliusccbbf8d2016-08-10 07:34:28 -0700776 TimeSeries capture_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200777 capture_time_data.label = GetStreamName(stream_id) + " capture-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700778 capture_time_data.style = BAR_GRAPH;
779 Pairwise<NetworkDelayDiff::CaptureTime>(packet_stream, begin_time_,
780 &capture_time_data);
781 plot->series_list_.push_back(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700782
tereliusccbbf8d2016-08-10 07:34:28 -0700783 TimeSeries send_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200784 send_time_data.label = GetStreamName(stream_id) + " abs-send-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700785 send_time_data.style = BAR_GRAPH;
786 Pairwise<NetworkDelayDiff::AbsSendTime>(packet_stream, begin_time_,
787 &send_time_data);
788 plot->series_list_.push_back(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700789 }
790
tereliusdc35dcd2016-08-01 12:03:27 -0700791 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
792 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
793 kTopMargin);
794 plot->SetTitle("Network latency change between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700795}
796
797void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700798 for (auto& kv : rtp_packets_) {
799 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700800 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700801 // Filter on direction and SSRC.
802 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200803 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
804 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
805 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700806 continue;
807 }
terelius54ce6802016-07-13 06:44:41 -0700808
tereliusccbbf8d2016-08-10 07:34:28 -0700809 TimeSeries capture_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200810 capture_time_data.label = GetStreamName(stream_id) + " capture-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700811 capture_time_data.style = LINE_GRAPH;
812 Pairwise<Accumulated<NetworkDelayDiff::CaptureTime>>(
813 packet_stream, begin_time_, &capture_time_data);
814 plot->series_list_.push_back(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700815
tereliusccbbf8d2016-08-10 07:34:28 -0700816 TimeSeries send_time_data;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200817 send_time_data.label = GetStreamName(stream_id) + " abs-send-time";
tereliusccbbf8d2016-08-10 07:34:28 -0700818 send_time_data.style = LINE_GRAPH;
819 Pairwise<Accumulated<NetworkDelayDiff::AbsSendTime>>(
820 packet_stream, begin_time_, &send_time_data);
821 plot->series_list_.push_back(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700822 }
823
tereliusdc35dcd2016-08-01 12:03:27 -0700824 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
825 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
826 kTopMargin);
827 plot->SetTitle("Accumulated network latency change");
terelius54ce6802016-07-13 06:44:41 -0700828}
829
tereliusf736d232016-08-04 10:00:11 -0700830// Plot the fraction of packets lost (as perceived by the loss-based BWE).
831void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
832 plot->series_list_.push_back(TimeSeries());
833 for (auto& bwe_update : bwe_loss_updates_) {
834 float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
835 float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100;
836 plot->series_list_.back().points.emplace_back(x, y);
837 }
838 plot->series_list_.back().label = "Fraction lost";
839 plot->series_list_.back().style = LINE_DOT_GRAPH;
840
841 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
842 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
843 kTopMargin);
844 plot->SetTitle("Reported packet loss");
845}
846
terelius54ce6802016-07-13 06:44:41 -0700847// Plot the total bandwidth used by all RTP streams.
848void EventLogAnalyzer::CreateTotalBitrateGraph(
849 PacketDirection desired_direction,
850 Plot* plot) {
851 struct TimestampSize {
852 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
853 uint64_t timestamp;
854 size_t size;
855 };
856 std::vector<TimestampSize> packets;
857
858 PacketDirection direction;
859 size_t total_length;
860
861 // Extract timestamps and sizes for the relevant packets.
862 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
863 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
864 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
865 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, nullptr,
866 &total_length);
867 if (direction == desired_direction) {
868 uint64_t timestamp = parsed_log_.GetTimestamp(i);
869 packets.push_back(TimestampSize(timestamp, total_length));
870 }
871 }
872 }
873
874 size_t window_index_begin = 0;
875 size_t window_index_end = 0;
876 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700877
878 // Calculate a moving average of the bitrate and store in a TimeSeries.
tereliusdc35dcd2016-08-01 12:03:27 -0700879 plot->series_list_.push_back(TimeSeries());
terelius54ce6802016-07-13 06:44:41 -0700880 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
881 while (window_index_end < packets.size() &&
882 packets[window_index_end].timestamp < time) {
883 bytes_in_window += packets[window_index_end].size;
terelius6addf492016-08-23 17:34:07 -0700884 ++window_index_end;
terelius54ce6802016-07-13 06:44:41 -0700885 }
886 while (window_index_begin < packets.size() &&
887 packets[window_index_begin].timestamp < time - window_duration_) {
888 RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window);
889 bytes_in_window -= packets[window_index_begin].size;
terelius6addf492016-08-23 17:34:07 -0700890 ++window_index_begin;
terelius54ce6802016-07-13 06:44:41 -0700891 }
892 float window_duration_in_seconds =
893 static_cast<float>(window_duration_) / 1000000;
894 float x = static_cast<float>(time - begin_time_) / 1000000;
895 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
tereliusdc35dcd2016-08-01 12:03:27 -0700896 plot->series_list_.back().points.push_back(TimeSeriesPoint(x, y));
terelius54ce6802016-07-13 06:44:41 -0700897 }
898
899 // Set labels.
900 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700901 plot->series_list_.back().label = "Incoming bitrate";
terelius54ce6802016-07-13 06:44:41 -0700902 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700903 plot->series_list_.back().label = "Outgoing bitrate";
terelius54ce6802016-07-13 06:44:41 -0700904 }
tereliusdc35dcd2016-08-01 12:03:27 -0700905 plot->series_list_.back().style = LINE_GRAPH;
terelius54ce6802016-07-13 06:44:41 -0700906
terelius8058e582016-07-25 01:32:41 -0700907 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
908 if (desired_direction == kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700909 plot->series_list_.push_back(TimeSeries());
terelius8058e582016-07-25 01:32:41 -0700910 for (auto& bwe_update : bwe_loss_updates_) {
911 float x =
912 static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
913 float y = static_cast<float>(bwe_update.new_bitrate) / 1000;
tereliusdc35dcd2016-08-01 12:03:27 -0700914 plot->series_list_.back().points.emplace_back(x, y);
terelius8058e582016-07-25 01:32:41 -0700915 }
tereliusdc35dcd2016-08-01 12:03:27 -0700916 plot->series_list_.back().label = "Loss-based estimate";
terelius77f05802017-02-01 06:34:53 -0800917 plot->series_list_.back().style = LINE_STEP_GRAPH;
terelius8058e582016-07-25 01:32:41 -0700918 }
tereliusdc35dcd2016-08-01 12:03:27 -0700919 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
920 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700921 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700922 plot->SetTitle("Incoming RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -0700923 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700924 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -0700925 }
926}
927
928// For each SSRC, plot the bandwidth used by that stream.
929void EventLogAnalyzer::CreateStreamBitrateGraph(
930 PacketDirection desired_direction,
931 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700932 for (auto& kv : rtp_packets_) {
933 StreamId stream_id = kv.first;
934 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
935 // Filter on direction and SSRC.
936 if (stream_id.GetDirection() != desired_direction ||
937 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
938 continue;
terelius54ce6802016-07-13 06:44:41 -0700939 }
940
terelius6addf492016-08-23 17:34:07 -0700941 TimeSeries time_series;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200942 time_series.label = GetStreamName(stream_id);
terelius6addf492016-08-23 17:34:07 -0700943 time_series.style = LINE_GRAPH;
944 double bytes_to_kilobits = 8.0 / 1000;
945 MovingAverage<PacketSizeBytes>(packet_stream, begin_time_, end_time_,
946 window_duration_, step_, bytes_to_kilobits,
947 &time_series);
948 plot->series_list_.push_back(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700949 }
950
tereliusdc35dcd2016-08-01 12:03:27 -0700951 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
952 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700953 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700954 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -0700955 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700956 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -0700957 }
958}
959
tereliuse34c19c2016-08-15 08:47:14 -0700960void EventLogAnalyzer::CreateBweSimulationGraph(Plot* plot) {
Stefan Holmer13181032016-07-29 14:48:54 +0200961 std::map<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
962 std::map<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
963
964 for (const auto& kv : rtp_packets_) {
965 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
966 for (const LoggedRtpPacket& rtp_packet : kv.second)
967 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
968 }
969 }
970
971 for (const auto& kv : rtcp_packets_) {
972 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
973 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
974 incoming_rtcp.insert(
975 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
976 }
977 }
978
979 SimulatedClock clock(0);
980 BitrateObserver observer;
981 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -0800982 PacketRouter packet_router;
983 CongestionController cc(&clock, &observer, &observer, &null_event_log,
984 &packet_router);
Stefan Holmer13181032016-07-29 14:48:54 +0200985 // TODO(holmer): Log the call config and use that here instead.
986 static const uint32_t kDefaultStartBitrateBps = 300000;
987 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
988
989 TimeSeries time_series;
tereliuse34c19c2016-08-15 08:47:14 -0700990 time_series.label = "Delay-based estimate";
Stefan Holmer13181032016-07-29 14:48:54 +0200991 time_series.style = LINE_DOT_GRAPH;
Stefan Holmer60e43462016-09-07 09:58:20 +0200992 TimeSeries acked_time_series;
993 acked_time_series.label = "Acked bitrate";
994 acked_time_series.style = LINE_DOT_GRAPH;
Stefan Holmer13181032016-07-29 14:48:54 +0200995
996 auto rtp_iterator = outgoing_rtp.begin();
997 auto rtcp_iterator = incoming_rtcp.begin();
998
999 auto NextRtpTime = [&]() {
1000 if (rtp_iterator != outgoing_rtp.end())
1001 return static_cast<int64_t>(rtp_iterator->first);
1002 return std::numeric_limits<int64_t>::max();
1003 };
1004
1005 auto NextRtcpTime = [&]() {
1006 if (rtcp_iterator != incoming_rtcp.end())
1007 return static_cast<int64_t>(rtcp_iterator->first);
1008 return std::numeric_limits<int64_t>::max();
1009 };
1010
1011 auto NextProcessTime = [&]() {
1012 if (rtcp_iterator != incoming_rtcp.end() ||
1013 rtp_iterator != outgoing_rtp.end()) {
1014 return clock.TimeInMicroseconds() +
1015 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
1016 }
1017 return std::numeric_limits<int64_t>::max();
1018 };
1019
Stefan Holmer492ee282016-10-27 17:19:20 +02001020 RateStatistics acked_bitrate(250, 8000);
Stefan Holmer60e43462016-09-07 09:58:20 +02001021
Stefan Holmer13181032016-07-29 14:48:54 +02001022 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
Stefan Holmer492ee282016-10-27 17:19:20 +02001023 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001024 while (time_us != std::numeric_limits<int64_t>::max()) {
1025 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1026 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001027 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001028 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1029 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001030 TransportFeedbackObserver* observer = cc.GetTransportFeedbackObserver();
1031 observer->OnTransportFeedback(*static_cast<rtcp::TransportFeedback*>(
1032 rtcp.packet.get()));
1033 std::vector<PacketInfo> feedback =
1034 observer->GetTransportFeedbackVector();
1035 rtc::Optional<uint32_t> bitrate_bps;
1036 if (!feedback.empty()) {
1037 for (const PacketInfo& packet : feedback)
1038 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1039 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1040 }
1041 uint32_t y = 0;
1042 if (bitrate_bps)
1043 y = *bitrate_bps / 1000;
1044 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1045 1000000;
1046 acked_time_series.points.emplace_back(x, y);
Stefan Holmer13181032016-07-29 14:48:54 +02001047 }
1048 ++rtcp_iterator;
1049 }
1050 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001051 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001052 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1053 if (rtp.header.extension.hasTransportSequenceNumber) {
1054 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
1055 cc.GetTransportFeedbackObserver()->AddPacket(
stefana93d5ac2016-08-17 02:14:32 -07001056 rtp.header.extension.transportSequenceNumber, rtp.total_length,
philipelc7bf32a2017-02-17 03:59:43 -08001057 PacedPacketInfo::kNotAProbe);
Stefan Holmer13181032016-07-29 14:48:54 +02001058 rtc::SentPacket sent_packet(
1059 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1060 cc.OnSentPacket(sent_packet);
1061 }
1062 ++rtp_iterator;
1063 }
stefanc3de0332016-08-02 07:22:17 -07001064 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1065 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001066 cc.Process();
stefanc3de0332016-08-02 07:22:17 -07001067 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001068 if (observer.GetAndResetBitrateUpdated() ||
1069 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001070 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer13181032016-07-29 14:48:54 +02001071 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1072 1000000;
1073 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001074 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001075 }
1076 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1077 }
1078 // Add the data set to the plot.
tereliusdc35dcd2016-08-01 12:03:27 -07001079 plot->series_list_.push_back(std::move(time_series));
Stefan Holmer60e43462016-09-07 09:58:20 +02001080 plot->series_list_.push_back(std::move(acked_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001081
tereliusdc35dcd2016-08-01 12:03:27 -07001082 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1083 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1084 plot->SetTitle("Simulated BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001085}
1086
Stefan Holmer280de9e2016-09-30 10:06:51 +02001087// TODO(holmer): Remove once TransportFeedbackAdapter no longer needs a
1088// BitrateController.
1089class NullBitrateController : public BitrateController {
1090 public:
1091 ~NullBitrateController() override {}
1092 RtcpBandwidthObserver* CreateRtcpBandwidthObserver() override {
1093 return nullptr;
1094 }
1095 void SetStartBitrate(int start_bitrate_bps) override {}
1096 void SetMinMaxBitrate(int min_bitrate_bps, int max_bitrate_bps) override {}
1097 void SetBitrates(int start_bitrate_bps,
1098 int min_bitrate_bps,
1099 int max_bitrate_bps) override {}
1100 void ResetBitrates(int bitrate_bps,
1101 int min_bitrate_bps,
1102 int max_bitrate_bps) override {}
1103 void OnDelayBasedBweResult(const DelayBasedBwe::Result& result) override {}
1104 bool AvailableBandwidth(uint32_t* bandwidth) const override { return false; }
1105 void SetReservedBitrate(uint32_t reserved_bitrate_bps) override {}
1106 bool GetNetworkParameters(uint32_t* bitrate,
1107 uint8_t* fraction_loss,
1108 int64_t* rtt) override {
1109 return false;
1110 }
1111 int64_t TimeUntilNextProcess() override { return 0; }
1112 void Process() override {}
1113};
1114
tereliuse34c19c2016-08-15 08:47:14 -07001115void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanc3de0332016-08-02 07:22:17 -07001116 std::map<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1117 std::map<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
1118
1119 for (const auto& kv : rtp_packets_) {
1120 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1121 for (const LoggedRtpPacket& rtp_packet : kv.second)
1122 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1123 }
1124 }
1125
1126 for (const auto& kv : rtcp_packets_) {
1127 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1128 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1129 incoming_rtcp.insert(
1130 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1131 }
1132 }
1133
1134 SimulatedClock clock(0);
Stefan Holmer280de9e2016-09-30 10:06:51 +02001135 NullBitrateController null_controller;
terelius0baf55d2017-02-17 03:38:28 -08001136 TransportFeedbackAdapter feedback_adapter(nullptr, &clock, &null_controller);
stefan41aab322016-10-10 08:16:30 -07001137 feedback_adapter.InitBwe();
stefanc3de0332016-08-02 07:22:17 -07001138
1139 TimeSeries time_series;
1140 time_series.label = "Network Delay Change";
1141 time_series.style = LINE_DOT_GRAPH;
1142 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
1143
1144 auto rtp_iterator = outgoing_rtp.begin();
1145 auto rtcp_iterator = incoming_rtcp.begin();
1146
1147 auto NextRtpTime = [&]() {
1148 if (rtp_iterator != outgoing_rtp.end())
1149 return static_cast<int64_t>(rtp_iterator->first);
1150 return std::numeric_limits<int64_t>::max();
1151 };
1152
1153 auto NextRtcpTime = [&]() {
1154 if (rtcp_iterator != incoming_rtcp.end())
1155 return static_cast<int64_t>(rtcp_iterator->first);
1156 return std::numeric_limits<int64_t>::max();
1157 };
1158
1159 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
1160 while (time_us != std::numeric_limits<int64_t>::max()) {
1161 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1162 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
1163 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
1164 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1165 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001166 feedback_adapter.OnTransportFeedback(
1167 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
stefanc3de0332016-08-02 07:22:17 -07001168 std::vector<PacketInfo> feedback =
Stefan Holmer60e43462016-09-07 09:58:20 +02001169 feedback_adapter.GetTransportFeedbackVector();
stefanc3de0332016-08-02 07:22:17 -07001170 for (const PacketInfo& packet : feedback) {
1171 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1172 float x =
1173 static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1174 1000000;
1175 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
1176 time_series.points.emplace_back(x, y);
1177 }
1178 }
1179 ++rtcp_iterator;
1180 }
1181 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1182 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1183 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1184 if (rtp.header.extension.hasTransportSequenceNumber) {
1185 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
1186 feedback_adapter.AddPacket(rtp.header.extension.transportSequenceNumber,
philipelc7bf32a2017-02-17 03:59:43 -08001187 rtp.total_length,
1188 PacedPacketInfo::kNotAProbe);
stefanc3de0332016-08-02 07:22:17 -07001189 feedback_adapter.OnSentPacket(
1190 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1191 }
1192 ++rtp_iterator;
1193 }
1194 time_us = std::min(NextRtpTime(), NextRtcpTime());
1195 }
1196 // We assume that the base network delay (w/o queues) is the min delay
1197 // observed during the call.
1198 for (TimeSeriesPoint& point : time_series.points)
1199 point.y -= estimated_base_delay_ms;
1200 // Add the data set to the plot.
1201 plot->series_list_.push_back(std::move(time_series));
1202
1203 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1204 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1205 plot->SetTitle("Network Delay Change.");
1206}
stefan08383272016-12-20 08:51:52 -08001207
1208std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps()
1209 const {
1210 std::vector<std::pair<int64_t, int64_t>> timestamps;
1211 size_t largest_stream_size = 0;
1212 const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr;
1213 // Find the incoming video stream with the most number of packets that is
1214 // not rtx.
1215 for (const auto& kv : rtp_packets_) {
1216 if (kv.first.GetDirection() == kIncomingPacket &&
1217 video_ssrcs_.find(kv.first) != video_ssrcs_.end() &&
1218 rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() &&
1219 kv.second.size() > largest_stream_size) {
1220 largest_stream_size = kv.second.size();
1221 largest_video_stream = &kv.second;
1222 }
1223 }
1224 if (largest_video_stream == nullptr) {
1225 for (auto& packet : *largest_video_stream) {
1226 if (packet.header.markerBit) {
1227 int64_t capture_ms = packet.header.timestamp / 90.0;
1228 int64_t arrival_ms = packet.timestamp / 1000.0;
1229 timestamps.push_back(std::make_pair(capture_ms, arrival_ms));
1230 }
1231 }
1232 }
1233 return timestamps;
1234}
stefane372d3c2017-02-02 08:04:18 -08001235
1236void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) {
1237 for (const auto& kv : rtp_packets_) {
1238 const std::vector<LoggedRtpPacket>& rtp_packets = kv.second;
1239 StreamId stream_id = kv.first;
1240
1241 {
1242 TimeSeries timestamp_data;
1243 timestamp_data.label = GetStreamName(stream_id) + " capture-time";
1244 timestamp_data.style = LINE_DOT_GRAPH;
1245 for (LoggedRtpPacket packet : rtp_packets) {
1246 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1247 float y = packet.header.timestamp;
1248 timestamp_data.points.emplace_back(x, y);
1249 }
1250 plot->series_list_.push_back(std::move(timestamp_data));
1251 }
1252
1253 {
1254 auto kv = rtcp_packets_.find(stream_id);
1255 if (kv != rtcp_packets_.end()) {
1256 const auto& packets = kv->second;
1257 TimeSeries timestamp_data;
1258 timestamp_data.label = GetStreamName(stream_id) + " rtcp capture-time";
1259 timestamp_data.style = LINE_DOT_GRAPH;
1260 for (const LoggedRtcpPacket& rtcp : packets) {
1261 if (rtcp.type != kRtcpSr)
1262 continue;
1263 rtcp::SenderReport* sr;
1264 sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get());
1265 float x = static_cast<float>(rtcp.timestamp - begin_time_) / 1000000;
1266 float y = sr->rtp_timestamp();
1267 timestamp_data.points.emplace_back(x, y);
1268 }
1269 plot->series_list_.push_back(std::move(timestamp_data));
1270 }
1271 }
1272 }
1273
1274 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1275 plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin);
1276 plot->SetTitle("Timestamps");
1277}
terelius54ce6802016-07-13 06:44:41 -07001278} // namespace plotting
1279} // namespace webrtc