blob: bab2914f16cd311343a6d8551f0c2748297f1707 [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
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "rtc_tools/event_log_visualizer/analyzer.h"
terelius54ce6802016-07-13 06:44:41 -070012
13#include <algorithm>
Oleh Prypin6581f212017-11-16 00:17:05 +010014#include <cmath>
terelius54ce6802016-07-13 06:44:41 -070015#include <limits>
16#include <map>
17#include <sstream>
18#include <string>
19#include <utility>
20
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "call/audio_receive_stream.h"
22#include "call/audio_send_stream.h"
23#include "call/call.h"
24#include "call/video_receive_stream.h"
25#include "call/video_send_stream.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020026#include "common_types.h" // NOLINT(build/include)
Elad Alon99a81b62017-09-21 10:25:29 +020027#include "logging/rtc_event_log/rtc_stream_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "modules/audio_coding/neteq/tools/audio_sink.h"
29#include "modules/audio_coding/neteq/tools/fake_decode_from_file.h"
30#include "modules/audio_coding/neteq/tools/neteq_delay_analyzer.h"
31#include "modules/audio_coding/neteq/tools/neteq_replacement_input.h"
32#include "modules/audio_coding/neteq/tools/neteq_test.h"
33#include "modules/audio_coding/neteq/tools/resample_input_audio_file.h"
Danil Chapovalovbda50682018-02-14 09:08:28 +000034#include "modules/congestion_controller/acknowledged_bitrate_estimator.h"
35#include "modules/congestion_controller/bitrate_estimator.h"
Sebastian Jansson439f0bc2018-02-20 10:46:39 +010036#include "modules/congestion_controller/delay_based_bwe.h"
Bjorn Terelius28db2662017-10-04 14:22:43 +020037#include "modules/congestion_controller/include/receive_side_congestion_controller.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020038#include "modules/congestion_controller/include/send_side_congestion_controller.h"
39#include "modules/include/module_common_types.h"
Niels Möllerfd6c0912017-10-31 10:19:10 +010040#include "modules/pacing/packet_router.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020041#include "modules/rtp_rtcp/include/rtp_rtcp.h"
42#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
43#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
44#include "modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
45#include "modules/rtp_rtcp/source/rtcp_packet/remb.h"
46#include "modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
47#include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
48#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
49#include "modules/rtp_rtcp/source/rtp_utility.h"
50#include "rtc_base/checks.h"
51#include "rtc_base/format_macros.h"
52#include "rtc_base/logging.h"
Bjorn Terelius0295a962017-10-25 17:42:41 +020053#include "rtc_base/numerics/sequence_number_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020054#include "rtc_base/ptr_util.h"
55#include "rtc_base/rate_statistics.h"
terelius54ce6802016-07-13 06:44:41 -070056
Bjorn Terelius6984ad22017-10-24 12:19:45 +020057#ifndef BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
58#define BWE_TEST_LOGGING_COMPILE_TIME_ENABLE 0
59#endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
60
tereliusdc35dcd2016-08-01 12:03:27 -070061namespace webrtc {
62namespace plotting {
63
terelius54ce6802016-07-13 06:44:41 -070064namespace {
65
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080066const int kNumMicrosecsPerSec = 1000000;
67
elad.alonec304f92017-03-08 05:03:53 -080068void SortPacketFeedbackVector(std::vector<PacketFeedback>* vec) {
69 auto pred = [](const PacketFeedback& packet_feedback) {
70 return packet_feedback.arrival_time_ms == PacketFeedback::kNotReceived;
71 };
72 vec->erase(std::remove_if(vec->begin(), vec->end(), pred), vec->end());
73 std::sort(vec->begin(), vec->end(), PacketFeedbackComparator());
74}
75
terelius54ce6802016-07-13 06:44:41 -070076std::string SsrcToString(uint32_t ssrc) {
77 std::stringstream ss;
78 ss << "SSRC " << ssrc;
79 return ss.str();
80}
81
82// Checks whether an SSRC is contained in the list of desired SSRCs.
83// Note that an empty SSRC list matches every SSRC.
84bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
85 if (desired_ssrc.size() == 0)
86 return true;
87 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
88 desired_ssrc.end();
89}
90
91double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
92 // The timestamp is a fixed point representation with 6 bits for seconds
93 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080094 // time in seconds and then multiply by kNumMicrosecsPerSec to convert to
95 // microseconds.
terelius54ce6802016-07-13 06:44:41 -070096 static constexpr double kTimestampToMicroSec =
Qingsi Wang8eca1ff2018-02-02 11:49:44 -080097 static_cast<double>(kNumMicrosecsPerSec) / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -070098 return abs_send_time * kTimestampToMicroSec;
99}
100
101// Computes the difference |later| - |earlier| where |later| and |earlier|
102// are counters that wrap at |modulus|. The difference is chosen to have the
103// least absolute value. For example if |modulus| is 8, then the difference will
104// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
105// be in [-4, 4].
106int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
107 RTC_DCHECK_LE(1, modulus);
108 RTC_DCHECK_LT(later, modulus);
109 RTC_DCHECK_LT(earlier, modulus);
110 int64_t difference =
111 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
112 int64_t max_difference = modulus / 2;
113 int64_t min_difference = max_difference - modulus + 1;
114 if (difference > max_difference) {
115 difference -= modulus;
116 }
117 if (difference < min_difference) {
118 difference += modulus;
119 }
terelius6addf492016-08-23 17:34:07 -0700120 if (difference > max_difference / 2 || difference < min_difference / 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100121 RTC_LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
122 << " expected to be in the range ("
123 << min_difference / 2 << "," << max_difference / 2
124 << ") but is " << difference
125 << ". Correct unwrapping is uncertain.";
terelius6addf492016-08-23 17:34:07 -0700126 }
terelius54ce6802016-07-13 06:44:41 -0700127 return difference;
128}
129
ivocaac9d6f2016-09-22 07:01:47 -0700130// Return default values for header extensions, to use on streams without stored
131// mapping data. Currently this only applies to audio streams, since the mapping
132// is not stored in the event log.
133// TODO(ivoc): Remove this once this mapping is stored in the event log for
134// audio streams. Tracking bug: webrtc:6399
135webrtc::RtpHeaderExtensionMap GetDefaultHeaderExtensionMap() {
136 webrtc::RtpHeaderExtensionMap default_map;
danilchap4aecc582016-11-15 09:21:00 -0800137 default_map.Register<AudioLevel>(webrtc::RtpExtension::kAudioLevelDefaultId);
terelius007d5622017-08-08 05:40:26 -0700138 default_map.Register<TransmissionOffset>(
139 webrtc::RtpExtension::kTimestampOffsetDefaultId);
danilchap4aecc582016-11-15 09:21:00 -0800140 default_map.Register<AbsoluteSendTime>(
ivocaac9d6f2016-09-22 07:01:47 -0700141 webrtc::RtpExtension::kAbsSendTimeDefaultId);
terelius007d5622017-08-08 05:40:26 -0700142 default_map.Register<VideoOrientation>(
143 webrtc::RtpExtension::kVideoRotationDefaultId);
144 default_map.Register<VideoContentTypeExtension>(
145 webrtc::RtpExtension::kVideoContentTypeDefaultId);
146 default_map.Register<VideoTimingExtension>(
147 webrtc::RtpExtension::kVideoTimingDefaultId);
148 default_map.Register<TransportSequenceNumber>(
149 webrtc::RtpExtension::kTransportSequenceNumberDefaultId);
150 default_map.Register<PlayoutDelayLimits>(
151 webrtc::RtpExtension::kPlayoutDelayDefaultId);
ivocaac9d6f2016-09-22 07:01:47 -0700152 return default_map;
153}
154
tereliusdc35dcd2016-08-01 12:03:27 -0700155constexpr float kLeftMargin = 0.01f;
156constexpr float kRightMargin = 0.02f;
157constexpr float kBottomMargin = 0.02f;
158constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700159
terelius53dc23c2017-03-13 05:24:05 -0700160rtc::Optional<double> NetworkDelayDiff_AbsSendTime(
161 const LoggedRtpPacket& old_packet,
162 const LoggedRtpPacket& new_packet) {
163 if (old_packet.header.extension.hasAbsoluteSendTime &&
164 new_packet.header.extension.hasAbsoluteSendTime) {
165 int64_t send_time_diff = WrappingDifference(
166 new_packet.header.extension.absoluteSendTime,
167 old_packet.header.extension.absoluteSendTime, 1ul << 24);
168 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
169 double delay_change_us =
170 recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff);
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100171 return delay_change_us / 1000;
terelius53dc23c2017-03-13 05:24:05 -0700172 } else {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100173 return rtc::nullopt;
terelius6addf492016-08-23 17:34:07 -0700174 }
175}
176
terelius53dc23c2017-03-13 05:24:05 -0700177rtc::Optional<double> NetworkDelayDiff_CaptureTime(
178 const LoggedRtpPacket& old_packet,
179 const LoggedRtpPacket& new_packet) {
180 int64_t send_time_diff = WrappingDifference(
181 new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32);
182 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
183
184 const double kVideoSampleRate = 90000;
185 // TODO(terelius): We treat all streams as video for now, even though
186 // audio might be sampled at e.g. 16kHz, because it is really difficult to
187 // figure out the true sampling rate of a stream. The effect is that the
188 // delay will be scaled incorrectly for non-video streams.
189
190 double delay_change =
191 static_cast<double>(recv_time_diff) / 1000 -
192 static_cast<double>(send_time_diff) / kVideoSampleRate * 1000;
193 if (delay_change < -10000 || 10000 < delay_change) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100194 RTC_LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
195 RTC_LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp
196 << ", received time " << old_packet.timestamp;
197 RTC_LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp
198 << ", received time " << new_packet.timestamp;
199 RTC_LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800200 << static_cast<double>(recv_time_diff) /
201 kNumMicrosecsPerSec
202 << "s";
Mirko Bonadei675513b2017-11-09 11:09:25 +0100203 RTC_LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
204 << static_cast<double>(send_time_diff) /
205 kVideoSampleRate
206 << "s";
terelius53dc23c2017-03-13 05:24:05 -0700207 }
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100208 return delay_change;
terelius53dc23c2017-03-13 05:24:05 -0700209}
210
211// For each element in data, use |get_y()| to extract a y-coordinate and
212// store the result in a TimeSeries.
213template <typename DataType>
214void ProcessPoints(
215 rtc::FunctionView<rtc::Optional<float>(const DataType&)> get_y,
216 const std::vector<DataType>& data,
217 uint64_t begin_time,
218 TimeSeries* result) {
219 for (size_t i = 0; i < data.size(); i++) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800220 float x = static_cast<float>(data[i].timestamp - begin_time) /
221 kNumMicrosecsPerSec;
terelius53dc23c2017-03-13 05:24:05 -0700222 rtc::Optional<float> y = get_y(data[i]);
223 if (y)
224 result->points.emplace_back(x, *y);
225 }
226}
227
228// For each pair of adjacent elements in |data|, use |get_y| to extract a
terelius6addf492016-08-23 17:34:07 -0700229// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
230// will be the time of the second element in the pair.
terelius53dc23c2017-03-13 05:24:05 -0700231template <typename DataType, typename ResultType>
232void ProcessPairs(
233 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&,
234 const DataType&)> get_y,
235 const std::vector<DataType>& data,
236 uint64_t begin_time,
237 TimeSeries* result) {
tereliusccbbf8d2016-08-10 07:34:28 -0700238 for (size_t i = 1; i < data.size(); i++) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800239 float x = static_cast<float>(data[i].timestamp - begin_time) /
240 kNumMicrosecsPerSec;
terelius53dc23c2017-03-13 05:24:05 -0700241 rtc::Optional<ResultType> y = get_y(data[i - 1], data[i]);
242 if (y)
243 result->points.emplace_back(x, static_cast<float>(*y));
244 }
245}
246
247// For each element in data, use |extract()| to extract a y-coordinate and
248// store the result in a TimeSeries.
249template <typename DataType, typename ResultType>
250void AccumulatePoints(
251 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract,
252 const std::vector<DataType>& data,
253 uint64_t begin_time,
254 TimeSeries* result) {
255 ResultType sum = 0;
256 for (size_t i = 0; i < data.size(); i++) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800257 float x = static_cast<float>(data[i].timestamp - begin_time) /
258 kNumMicrosecsPerSec;
terelius53dc23c2017-03-13 05:24:05 -0700259 rtc::Optional<ResultType> y = extract(data[i]);
260 if (y) {
261 sum += *y;
262 result->points.emplace_back(x, static_cast<float>(sum));
263 }
264 }
265}
266
267// For each pair of adjacent elements in |data|, use |extract()| to extract a
268// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
269// will be the time of the second element in the pair.
270template <typename DataType, typename ResultType>
271void AccumulatePairs(
272 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&,
273 const DataType&)> extract,
274 const std::vector<DataType>& data,
275 uint64_t begin_time,
276 TimeSeries* result) {
277 ResultType sum = 0;
278 for (size_t i = 1; i < data.size(); i++) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800279 float x = static_cast<float>(data[i].timestamp - begin_time) /
280 kNumMicrosecsPerSec;
terelius53dc23c2017-03-13 05:24:05 -0700281 rtc::Optional<ResultType> y = extract(data[i - 1], data[i]);
282 if (y)
283 sum += *y;
284 result->points.emplace_back(x, static_cast<float>(sum));
tereliusccbbf8d2016-08-10 07:34:28 -0700285 }
286}
287
terelius6addf492016-08-23 17:34:07 -0700288// Calculates a moving average of |data| and stores the result in a TimeSeries.
289// A data point is generated every |step| microseconds from |begin_time|
290// to |end_time|. The value of each data point is the average of the data
291// during the preceeding |window_duration_us| microseconds.
terelius53dc23c2017-03-13 05:24:05 -0700292template <typename DataType, typename ResultType>
293void MovingAverage(
294 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract,
295 const std::vector<DataType>& data,
296 uint64_t begin_time,
297 uint64_t end_time,
298 uint64_t window_duration_us,
299 uint64_t step,
300 webrtc::plotting::TimeSeries* result) {
terelius6addf492016-08-23 17:34:07 -0700301 size_t window_index_begin = 0;
302 size_t window_index_end = 0;
terelius53dc23c2017-03-13 05:24:05 -0700303 ResultType sum_in_window = 0;
terelius6addf492016-08-23 17:34:07 -0700304
305 for (uint64_t t = begin_time; t < end_time + step; t += step) {
306 while (window_index_end < data.size() &&
307 data[window_index_end].timestamp < t) {
terelius53dc23c2017-03-13 05:24:05 -0700308 rtc::Optional<ResultType> value = extract(data[window_index_end]);
309 if (value)
310 sum_in_window += *value;
terelius6addf492016-08-23 17:34:07 -0700311 ++window_index_end;
312 }
313 while (window_index_begin < data.size() &&
314 data[window_index_begin].timestamp < t - window_duration_us) {
terelius53dc23c2017-03-13 05:24:05 -0700315 rtc::Optional<ResultType> value = extract(data[window_index_begin]);
316 if (value)
317 sum_in_window -= *value;
terelius6addf492016-08-23 17:34:07 -0700318 ++window_index_begin;
319 }
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800320 float window_duration_s =
321 static_cast<float>(window_duration_us) / kNumMicrosecsPerSec;
322 float x = static_cast<float>(t - begin_time) / kNumMicrosecsPerSec;
terelius53dc23c2017-03-13 05:24:05 -0700323 float y = sum_in_window / window_duration_s;
terelius6addf492016-08-23 17:34:07 -0700324 result->points.emplace_back(x, y);
325 }
326}
327
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800328const char kUnknownEnumValue[] = "unknown";
329
330const char kIceCandidateTypeLocal[] = "local";
331const char kIceCandidateTypeStun[] = "stun";
332const char kIceCandidateTypePrflx[] = "prflx";
333const char kIceCandidateTypeRelay[] = "relay";
334
335const char kProtocolUdp[] = "udp";
336const char kProtocolTcp[] = "tcp";
337const char kProtocolSsltcp[] = "ssltcp";
338const char kProtocolTls[] = "tls";
339
340const char kAddressFamilyIpv4[] = "ipv4";
341const char kAddressFamilyIpv6[] = "ipv6";
342
343const char kNetworkTypeEthernet[] = "ethernet";
344const char kNetworkTypeLoopback[] = "loopback";
345const char kNetworkTypeWifi[] = "wifi";
346const char kNetworkTypeVpn[] = "vpn";
347const char kNetworkTypeCellular[] = "cellular";
348
349std::string GetIceCandidateTypeAsString(webrtc::IceCandidateType type) {
350 switch (type) {
351 case webrtc::IceCandidateType::kLocal:
352 return kIceCandidateTypeLocal;
353 case webrtc::IceCandidateType::kStun:
354 return kIceCandidateTypeStun;
355 case webrtc::IceCandidateType::kPrflx:
356 return kIceCandidateTypePrflx;
357 case webrtc::IceCandidateType::kRelay:
358 return kIceCandidateTypeRelay;
359 default:
360 return kUnknownEnumValue;
361 }
362}
363
364std::string GetProtocolAsString(webrtc::IceCandidatePairProtocol protocol) {
365 switch (protocol) {
366 case webrtc::IceCandidatePairProtocol::kUdp:
367 return kProtocolUdp;
368 case webrtc::IceCandidatePairProtocol::kTcp:
369 return kProtocolTcp;
370 case webrtc::IceCandidatePairProtocol::kSsltcp:
371 return kProtocolSsltcp;
372 case webrtc::IceCandidatePairProtocol::kTls:
373 return kProtocolTls;
374 default:
375 return kUnknownEnumValue;
376 }
377}
378
379std::string GetAddressFamilyAsString(
380 webrtc::IceCandidatePairAddressFamily family) {
381 switch (family) {
382 case webrtc::IceCandidatePairAddressFamily::kIpv4:
383 return kAddressFamilyIpv4;
384 case webrtc::IceCandidatePairAddressFamily::kIpv6:
385 return kAddressFamilyIpv6;
386 default:
387 return kUnknownEnumValue;
388 }
389}
390
391std::string GetNetworkTypeAsString(webrtc::IceCandidateNetworkType type) {
392 switch (type) {
393 case webrtc::IceCandidateNetworkType::kEthernet:
394 return kNetworkTypeEthernet;
395 case webrtc::IceCandidateNetworkType::kLoopback:
396 return kNetworkTypeLoopback;
397 case webrtc::IceCandidateNetworkType::kWifi:
398 return kNetworkTypeWifi;
399 case webrtc::IceCandidateNetworkType::kVpn:
400 return kNetworkTypeVpn;
401 case webrtc::IceCandidateNetworkType::kCellular:
402 return kNetworkTypeCellular;
403 default:
404 return kUnknownEnumValue;
405 }
406}
407
408std::string GetCandidatePairLogDescriptionAsString(
409 const ParsedRtcEventLog::IceCandidatePairConfig& config) {
410 // Example: stun:wifi->relay(tcp):cellular@udp:ipv4
411 // represents a pair of a local server-reflexive candidate on a WiFi network
412 // and a remote relay candidate using TCP as the relay protocol on a cell
413 // network, when the candidate pair communicates over UDP using IPv4.
414 std::stringstream ss;
415 std::string local_candidate_type =
416 GetIceCandidateTypeAsString(config.local_candidate_type);
417 std::string remote_candidate_type =
418 GetIceCandidateTypeAsString(config.remote_candidate_type);
419 if (config.local_candidate_type == webrtc::IceCandidateType::kRelay) {
420 local_candidate_type +=
421 "(" + GetProtocolAsString(config.local_relay_protocol) + ")";
422 }
423 ss << local_candidate_type << ":"
424 << GetNetworkTypeAsString(config.local_network_type) << ":"
425 << GetAddressFamilyAsString(config.local_address_family) << "->"
426 << remote_candidate_type << ":"
427 << GetAddressFamilyAsString(config.remote_address_family) << "@"
428 << GetProtocolAsString(config.candidate_pair_protocol);
429 return ss.str();
430}
431
terelius54ce6802016-07-13 06:44:41 -0700432} // namespace
433
terelius54ce6802016-07-13 06:44:41 -0700434EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log)
435 : parsed_log_(log), window_duration_(250000), step_(10000) {
436 uint64_t first_timestamp = std::numeric_limits<uint64_t>::max();
437 uint64_t last_timestamp = std::numeric_limits<uint64_t>::min();
terelius88e64e52016-07-19 01:51:06 -0700438
terelius88e64e52016-07-19 01:51:06 -0700439 PacketDirection direction;
terelius88e64e52016-07-19 01:51:06 -0700440 uint8_t header[IP_PACKET_SIZE];
441 size_t header_length;
442 size_t total_length;
443
perkjbbbad6d2017-05-19 06:30:28 -0700444 uint8_t last_incoming_rtcp_packet[IP_PACKET_SIZE];
445 uint8_t last_incoming_rtcp_packet_length = 0;
446
ivocaac9d6f2016-09-22 07:01:47 -0700447 // Make a default extension map for streams without configuration information.
448 // TODO(ivoc): Once configuration of audio streams is stored in the event log,
449 // this can be removed. Tracking bug: webrtc:6399
450 RtpHeaderExtensionMap default_extension_map = GetDefaultHeaderExtensionMap();
451
henrik.lundin3c938fc2017-06-14 06:09:58 -0700452 rtc::Optional<uint64_t> last_log_start;
453
terelius54ce6802016-07-13 06:44:41 -0700454 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
455 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
terelius88e64e52016-07-19 01:51:06 -0700456 if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT &&
457 event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT &&
458 event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT &&
terelius88c1d2b2016-08-01 05:20:33 -0700459 event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT &&
460 event_type != ParsedRtcEventLog::LOG_START &&
461 event_type != ParsedRtcEventLog::LOG_END) {
terelius88e64e52016-07-19 01:51:06 -0700462 uint64_t timestamp = parsed_log_.GetTimestamp(i);
463 first_timestamp = std::min(first_timestamp, timestamp);
464 last_timestamp = std::max(last_timestamp, timestamp);
465 }
466
467 switch (parsed_log_.GetEventType(i)) {
468 case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700469 rtclog::StreamConfig config = parsed_log_.GetVideoReceiveConfig(i);
perkj09e71da2017-05-22 03:26:49 -0700470 StreamId stream(config.remote_ssrc, kIncomingPacket);
terelius0740a202016-08-08 10:21:04 -0700471 video_ssrcs_.insert(stream);
perkj09e71da2017-05-22 03:26:49 -0700472 StreamId rtx_stream(config.rtx_ssrc, kIncomingPacket);
brandtr14742122017-01-27 04:53:07 -0800473 video_ssrcs_.insert(rtx_stream);
474 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700475 break;
476 }
477 case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700478 std::vector<rtclog::StreamConfig> configs =
479 parsed_log_.GetVideoSendConfig(i);
terelius405f90c2017-06-01 03:50:31 -0700480 for (const auto& config : configs) {
481 StreamId stream(config.local_ssrc, kOutgoingPacket);
terelius8fbc7652017-05-31 02:03:16 -0700482 video_ssrcs_.insert(stream);
terelius405f90c2017-06-01 03:50:31 -0700483 StreamId rtx_stream(config.rtx_ssrc, kOutgoingPacket);
terelius8fbc7652017-05-31 02:03:16 -0700484 video_ssrcs_.insert(rtx_stream);
485 rtx_ssrcs_.insert(rtx_stream);
486 }
terelius88e64e52016-07-19 01:51:06 -0700487 break;
488 }
489 case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700490 rtclog::StreamConfig config = parsed_log_.GetAudioReceiveConfig(i);
perkjac8f52d2017-05-22 09:36:28 -0700491 StreamId stream(config.remote_ssrc, kIncomingPacket);
ivoce0928d82016-10-10 05:12:51 -0700492 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700493 break;
494 }
495 case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700496 rtclog::StreamConfig config = parsed_log_.GetAudioSendConfig(i);
perkjf4726992017-05-22 10:12:26 -0700497 StreamId stream(config.local_ssrc, kOutgoingPacket);
ivoce0928d82016-10-10 05:12:51 -0700498 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700499 break;
500 }
501 case ParsedRtcEventLog::RTP_EVENT: {
ilnika8e781a2017-06-12 01:02:46 -0700502 RtpHeaderExtensionMap* extension_map = parsed_log_.GetRtpHeader(
Elad Alon1d87b0e2017-10-03 15:01:03 +0200503 i, &direction, header, &header_length, &total_length, nullptr);
terelius88e64e52016-07-19 01:51:06 -0700504 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
505 RTPHeader parsed_header;
ilnika8e781a2017-06-12 01:02:46 -0700506 if (extension_map != nullptr) {
terelius88e64e52016-07-19 01:51:06 -0700507 rtp_parser.Parse(&parsed_header, extension_map);
ivocaac9d6f2016-09-22 07:01:47 -0700508 } else {
509 // Use the default extension map.
510 // TODO(ivoc): Once configuration of audio streams is stored in the
511 // event log, this can be removed.
512 // Tracking bug: webrtc:6399
513 rtp_parser.Parse(&parsed_header, &default_extension_map);
terelius88e64e52016-07-19 01:51:06 -0700514 }
515 uint64_t timestamp = parsed_log_.GetTimestamp(i);
ilnika8e781a2017-06-12 01:02:46 -0700516 StreamId stream(parsed_header.ssrc, direction);
terelius88e64e52016-07-19 01:51:06 -0700517 rtp_packets_[stream].push_back(
Stefan Holmer13181032016-07-29 14:48:54 +0200518 LoggedRtpPacket(timestamp, parsed_header, total_length));
terelius88e64e52016-07-19 01:51:06 -0700519 break;
520 }
521 case ParsedRtcEventLog::RTCP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200522 uint8_t packet[IP_PACKET_SIZE];
perkj77cd58e2017-05-30 03:52:10 -0700523 parsed_log_.GetRtcpPacket(i, &direction, packet, &total_length);
perkjbbbad6d2017-05-19 06:30:28 -0700524 // Currently incoming RTCP packets are logged twice, both for audio and
525 // video. Only act on one of them. Compare against the previous parsed
526 // incoming RTCP packet.
527 if (direction == webrtc::kIncomingPacket) {
528 RTC_CHECK_LE(total_length, IP_PACKET_SIZE);
529 if (total_length == last_incoming_rtcp_packet_length &&
530 memcmp(last_incoming_rtcp_packet, packet, total_length) == 0) {
531 continue;
532 } else {
533 memcpy(last_incoming_rtcp_packet, packet, total_length);
534 last_incoming_rtcp_packet_length = total_length;
535 }
536 }
537 rtcp::CommonHeader header;
538 const uint8_t* packet_end = packet + total_length;
539 for (const uint8_t* block = packet; block < packet_end;
540 block = header.NextPacket()) {
541 RTC_CHECK(header.Parse(block, packet_end - block));
542 if (header.type() == rtcp::TransportFeedback::kPacketType &&
543 header.fmt() == rtcp::TransportFeedback::kFeedbackMessageType) {
544 std::unique_ptr<rtcp::TransportFeedback> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700545 rtc::MakeUnique<rtcp::TransportFeedback>());
perkjbbbad6d2017-05-19 06:30:28 -0700546 if (rtcp_packet->Parse(header)) {
547 uint32_t ssrc = rtcp_packet->sender_ssrc();
548 StreamId stream(ssrc, direction);
549 uint64_t timestamp = parsed_log_.GetTimestamp(i);
550 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
551 timestamp, kRtcpTransportFeedback, std::move(rtcp_packet)));
552 }
553 } else if (header.type() == rtcp::SenderReport::kPacketType) {
554 std::unique_ptr<rtcp::SenderReport> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700555 rtc::MakeUnique<rtcp::SenderReport>());
perkjbbbad6d2017-05-19 06:30:28 -0700556 if (rtcp_packet->Parse(header)) {
557 uint32_t ssrc = rtcp_packet->sender_ssrc();
558 StreamId stream(ssrc, direction);
559 uint64_t timestamp = parsed_log_.GetTimestamp(i);
560 rtcp_packets_[stream].push_back(
561 LoggedRtcpPacket(timestamp, kRtcpSr, std::move(rtcp_packet)));
562 }
563 } else if (header.type() == rtcp::ReceiverReport::kPacketType) {
564 std::unique_ptr<rtcp::ReceiverReport> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700565 rtc::MakeUnique<rtcp::ReceiverReport>());
perkjbbbad6d2017-05-19 06:30:28 -0700566 if (rtcp_packet->Parse(header)) {
567 uint32_t ssrc = rtcp_packet->sender_ssrc();
568 StreamId stream(ssrc, direction);
569 uint64_t timestamp = parsed_log_.GetTimestamp(i);
570 rtcp_packets_[stream].push_back(
571 LoggedRtcpPacket(timestamp, kRtcpRr, std::move(rtcp_packet)));
Stefan Holmer13181032016-07-29 14:48:54 +0200572 }
terelius2c8e8a32017-06-02 01:29:48 -0700573 } else if (header.type() == rtcp::Remb::kPacketType &&
574 header.fmt() == rtcp::Remb::kFeedbackMessageType) {
575 std::unique_ptr<rtcp::Remb> rtcp_packet(
576 rtc::MakeUnique<rtcp::Remb>());
577 if (rtcp_packet->Parse(header)) {
578 uint32_t ssrc = rtcp_packet->sender_ssrc();
579 StreamId stream(ssrc, direction);
580 uint64_t timestamp = parsed_log_.GetTimestamp(i);
581 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
582 timestamp, kRtcpRemb, std::move(rtcp_packet)));
583 }
Stefan Holmer13181032016-07-29 14:48:54 +0200584 }
Stefan Holmer13181032016-07-29 14:48:54 +0200585 }
terelius88e64e52016-07-19 01:51:06 -0700586 break;
587 }
588 case ParsedRtcEventLog::LOG_START: {
henrik.lundin3c938fc2017-06-14 06:09:58 -0700589 if (last_log_start) {
590 // A LOG_END event was missing. Use last_timestamp.
591 RTC_DCHECK_GE(last_timestamp, *last_log_start);
592 log_segments_.push_back(
593 std::make_pair(*last_log_start, last_timestamp));
594 }
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100595 last_log_start = parsed_log_.GetTimestamp(i);
terelius88e64e52016-07-19 01:51:06 -0700596 break;
597 }
598 case ParsedRtcEventLog::LOG_END: {
henrik.lundin3c938fc2017-06-14 06:09:58 -0700599 RTC_DCHECK(last_log_start);
600 log_segments_.push_back(
601 std::make_pair(*last_log_start, parsed_log_.GetTimestamp(i)));
602 last_log_start.reset();
terelius88e64e52016-07-19 01:51:06 -0700603 break;
604 }
terelius424e6cf2017-02-20 05:14:41 -0800605 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: {
henrik.lundin3c938fc2017-06-14 06:09:58 -0700606 uint32_t this_ssrc;
607 parsed_log_.GetAudioPlayout(i, &this_ssrc);
608 audio_playout_events_[this_ssrc].push_back(parsed_log_.GetTimestamp(i));
terelius424e6cf2017-02-20 05:14:41 -0800609 break;
610 }
611 case ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE: {
612 LossBasedBweUpdate bwe_update;
terelius8058e582016-07-25 01:32:41 -0700613 bwe_update.timestamp = parsed_log_.GetTimestamp(i);
terelius424e6cf2017-02-20 05:14:41 -0800614 parsed_log_.GetLossBasedBweUpdate(i, &bwe_update.new_bitrate,
615 &bwe_update.fraction_loss,
616 &bwe_update.expected_packets);
terelius8058e582016-07-25 01:32:41 -0700617 bwe_loss_updates_.push_back(bwe_update);
terelius88e64e52016-07-19 01:51:06 -0700618 break;
619 }
terelius424e6cf2017-02-20 05:14:41 -0800620 case ParsedRtcEventLog::DELAY_BASED_BWE_UPDATE: {
philipel10fc0e62017-04-11 01:50:23 -0700621 bwe_delay_updates_.push_back(parsed_log_.GetDelayBasedBweUpdate(i));
terelius424e6cf2017-02-20 05:14:41 -0800622 break;
623 }
minyue4b7c9522017-01-24 04:54:59 -0800624 case ParsedRtcEventLog::AUDIO_NETWORK_ADAPTATION_EVENT: {
michaelt6e5b2192017-02-22 07:33:27 -0800625 AudioNetworkAdaptationEvent ana_event;
626 ana_event.timestamp = parsed_log_.GetTimestamp(i);
627 parsed_log_.GetAudioNetworkAdaptation(i, &ana_event.config);
628 audio_network_adaptation_events_.push_back(ana_event);
minyue4b7c9522017-01-24 04:54:59 -0800629 break;
630 }
philipel32d00102017-02-27 02:18:46 -0800631 case ParsedRtcEventLog::BWE_PROBE_CLUSTER_CREATED_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200632 bwe_probe_cluster_created_events_.push_back(
633 parsed_log_.GetBweProbeClusterCreated(i));
philipel32d00102017-02-27 02:18:46 -0800634 break;
635 }
636 case ParsedRtcEventLog::BWE_PROBE_RESULT_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200637 bwe_probe_result_events_.push_back(parsed_log_.GetBweProbeResult(i));
philipel32d00102017-02-27 02:18:46 -0800638 break;
639 }
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +0100640 case ParsedRtcEventLog::ALR_STATE_EVENT: {
641 alr_state_events_.push_back(parsed_log_.GetAlrState(i));
642 break;
643 }
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800644 case ParsedRtcEventLog::ICE_CANDIDATE_PAIR_CONFIG: {
645 ice_candidate_pair_configs_.push_back(
646 parsed_log_.GetIceCandidatePairConfig(i));
647 break;
648 }
649 case ParsedRtcEventLog::ICE_CANDIDATE_PAIR_EVENT: {
650 ice_candidate_pair_events_.push_back(
651 parsed_log_.GetIceCandidatePairEvent(i));
652 break;
653 }
terelius88e64e52016-07-19 01:51:06 -0700654 case ParsedRtcEventLog::UNKNOWN_EVENT: {
655 break;
656 }
657 }
terelius54ce6802016-07-13 06:44:41 -0700658 }
terelius88e64e52016-07-19 01:51:06 -0700659
terelius54ce6802016-07-13 06:44:41 -0700660 if (last_timestamp < first_timestamp) {
661 // No useful events in the log.
662 first_timestamp = last_timestamp = 0;
663 }
664 begin_time_ = first_timestamp;
665 end_time_ = last_timestamp;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800666 call_duration_s_ = ToCallTime(end_time_);
henrik.lundin3c938fc2017-06-14 06:09:58 -0700667 if (last_log_start) {
668 // The log was missing the last LOG_END event. Fake it.
669 log_segments_.push_back(std::make_pair(*last_log_start, end_time_));
670 }
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100671 RTC_LOG(LS_INFO) << "Found " << log_segments_.size()
672 << " (LOG_START, LOG_END) segments in log.";
terelius54ce6802016-07-13 06:44:41 -0700673}
674
Sebastian Janssone4be6da2018-02-15 16:51:41 +0100675class BitrateObserver : public NetworkChangedObserver,
Stefan Holmer13181032016-07-29 14:48:54 +0200676 public RemoteBitrateObserver {
677 public:
678 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
679
680 void OnNetworkChanged(uint32_t bitrate_bps,
681 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800682 int64_t rtt_ms,
683 int64_t probing_interval_ms) override {
Stefan Holmer13181032016-07-29 14:48:54 +0200684 last_bitrate_bps_ = bitrate_bps;
685 bitrate_updated_ = true;
686 }
687
688 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
689 uint32_t bitrate) override {}
690
691 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
692 bool GetAndResetBitrateUpdated() {
693 bool bitrate_updated = bitrate_updated_;
694 bitrate_updated_ = false;
695 return bitrate_updated;
696 }
697
698 private:
699 uint32_t last_bitrate_bps_;
700 bool bitrate_updated_;
701};
702
Stefan Holmer99f8e082016-09-09 13:37:50 +0200703bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700704 return rtx_ssrcs_.count(stream_id) == 1;
705}
706
Stefan Holmer99f8e082016-09-09 13:37:50 +0200707bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700708 return video_ssrcs_.count(stream_id) == 1;
709}
710
Stefan Holmer99f8e082016-09-09 13:37:50 +0200711bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700712 return audio_ssrcs_.count(stream_id) == 1;
713}
714
Stefan Holmer99f8e082016-09-09 13:37:50 +0200715std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const {
716 std::stringstream name;
717 if (IsAudioSsrc(stream_id)) {
718 name << "Audio ";
719 } else if (IsVideoSsrc(stream_id)) {
720 name << "Video ";
721 } else {
722 name << "Unknown ";
723 }
724 if (IsRtxSsrc(stream_id))
725 name << "RTX ";
ivocaac9d6f2016-09-22 07:01:47 -0700726 if (stream_id.GetDirection() == kIncomingPacket) {
727 name << "(In) ";
728 } else {
729 name << "(Out) ";
730 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200731 name << SsrcToString(stream_id.GetSsrc());
732 return name.str();
733}
734
Bjorn Terelius0295a962017-10-25 17:42:41 +0200735// This is much more reliable for outgoing streams than for incoming streams.
736rtc::Optional<uint32_t> EventLogAnalyzer::EstimateRtpClockFrequency(
737 const std::vector<LoggedRtpPacket>& packets) const {
738 RTC_CHECK(packets.size() >= 2);
739 uint64_t end_time_us = log_segments_.empty()
740 ? std::numeric_limits<uint64_t>::max()
741 : log_segments_.front().second;
742 SeqNumUnwrapper<uint32_t> unwrapper;
743 uint64_t first_rtp_timestamp = unwrapper.Unwrap(packets[0].header.timestamp);
744 uint64_t first_log_timestamp = packets[0].timestamp;
745 uint64_t last_rtp_timestamp = first_rtp_timestamp;
746 uint64_t last_log_timestamp = first_log_timestamp;
747 for (size_t i = 1; i < packets.size(); i++) {
748 if (packets[i].timestamp > end_time_us)
749 break;
750 last_rtp_timestamp = unwrapper.Unwrap(packets[i].header.timestamp);
751 last_log_timestamp = packets[i].timestamp;
752 }
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800753 if (last_log_timestamp - first_log_timestamp < kNumMicrosecsPerSec) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100754 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +0200755 << "Failed to estimate RTP clock frequency: Stream too short. ("
756 << packets.size() << " packets, "
757 << last_log_timestamp - first_log_timestamp << " us)";
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100758 return rtc::nullopt;
Bjorn Terelius0295a962017-10-25 17:42:41 +0200759 }
760 double duration =
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800761 static_cast<double>(last_log_timestamp - first_log_timestamp) /
762 kNumMicrosecsPerSec;
Bjorn Terelius0295a962017-10-25 17:42:41 +0200763 double estimated_frequency =
764 (last_rtp_timestamp - first_rtp_timestamp) / duration;
765 for (uint32_t f : {8000, 16000, 32000, 48000, 90000}) {
766 if (std::fabs(estimated_frequency - f) < 0.05 * f) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100767 return f;
Bjorn Terelius0295a962017-10-25 17:42:41 +0200768 }
769 }
Mirko Bonadei675513b2017-11-09 11:09:25 +0100770 RTC_LOG(LS_WARNING) << "Failed to estimate RTP clock frequency: Estimate "
771 << estimated_frequency
772 << "not close to any stardard RTP frequency.";
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100773 return rtc::nullopt;
Bjorn Terelius0295a962017-10-25 17:42:41 +0200774}
775
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100776float EventLogAnalyzer::ToCallTime(int64_t timestamp) const {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800777 return static_cast<float>(timestamp - begin_time_) / kNumMicrosecsPerSec;
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100778}
779
terelius54ce6802016-07-13 06:44:41 -0700780void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
781 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700782 for (auto& kv : rtp_packets_) {
783 StreamId stream_id = kv.first;
784 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
785 // Filter on direction and SSRC.
786 if (stream_id.GetDirection() != desired_direction ||
787 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
788 continue;
terelius54ce6802016-07-13 06:44:41 -0700789 }
terelius54ce6802016-07-13 06:44:41 -0700790
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100791 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700792 ProcessPoints<LoggedRtpPacket>(
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100793 [](const LoggedRtpPacket& packet) {
terelius53dc23c2017-03-13 05:24:05 -0700794 return rtc::Optional<float>(packet.total_length);
795 },
796 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700797 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700798 }
799
tereliusdc35dcd2016-08-01 12:03:27 -0700800 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
801 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
802 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700803 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700804 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700805 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700806 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700807 }
808}
809
philipelccd74892016-09-05 02:46:25 -0700810template <typename T>
811void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
812 PacketDirection desired_direction,
813 Plot* plot,
814 const std::map<StreamId, std::vector<T>>& packets,
815 const std::string& label_prefix) {
816 for (auto& kv : packets) {
817 StreamId stream_id = kv.first;
818 const std::vector<T>& packet_stream = kv.second;
819 // Filter on direction and SSRC.
820 if (stream_id.GetDirection() != desired_direction ||
821 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
822 continue;
823 }
824
terelius23c595a2017-03-15 01:59:12 -0700825 std::string label = label_prefix + " " + GetStreamName(stream_id);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100826 TimeSeries time_series(label, LineStyle::kStep);
philipelccd74892016-09-05 02:46:25 -0700827 for (size_t i = 0; i < packet_stream.size(); i++) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800828 float x = ToCallTime(packet_stream[i].timestamp);
philipelccd74892016-09-05 02:46:25 -0700829 time_series.points.emplace_back(x, i + 1);
830 }
831
philipel35ba9bd2017-04-19 05:58:51 -0700832 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700833 }
834}
835
836void EventLogAnalyzer::CreateAccumulatedPacketsGraph(
837 PacketDirection desired_direction,
838 Plot* plot) {
839 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_,
840 "RTP");
841 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_,
842 "RTCP");
843
844 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
845 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
846 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
847 plot->SetTitle("Accumulated Incoming RTP/RTCP packets");
848 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
849 plot->SetTitle("Accumulated Outgoing RTP/RTCP packets");
850 }
851}
852
terelius54ce6802016-07-13 06:44:41 -0700853// For each SSRC, plot the time between the consecutive playouts.
854void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
855 std::map<uint32_t, TimeSeries> time_series;
856 std::map<uint32_t, uint64_t> last_playout;
857
858 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700859
860 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
861 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
862 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
863 parsed_log_.GetAudioPlayout(i, &ssrc);
864 uint64_t timestamp = parsed_log_.GetTimestamp(i);
865 if (MatchingSsrc(ssrc, desired_ssrc_)) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800866 float x = ToCallTime(timestamp);
terelius54ce6802016-07-13 06:44:41 -0700867 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
868 if (time_series[ssrc].points.size() == 0) {
869 // There were no previusly logged playout for this SSRC.
870 // Generate a point, but place it on the x-axis.
871 y = 0;
872 }
terelius54ce6802016-07-13 06:44:41 -0700873 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
874 last_playout[ssrc] = timestamp;
875 }
876 }
877 }
878
879 // Set labels and put in graph.
880 for (auto& kv : time_series) {
881 kv.second.label = SsrcToString(kv.first);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100882 kv.second.line_style = LineStyle::kBar;
philipel35ba9bd2017-04-19 05:58:51 -0700883 plot->AppendTimeSeries(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700884 }
885
tereliusdc35dcd2016-08-01 12:03:27 -0700886 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
887 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
888 kTopMargin);
889 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700890}
891
ivocaac9d6f2016-09-22 07:01:47 -0700892// For audio SSRCs, plot the audio level.
893void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) {
894 std::map<StreamId, TimeSeries> time_series;
895
896 for (auto& kv : rtp_packets_) {
897 StreamId stream_id = kv.first;
898 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
899 // TODO(ivoc): When audio send/receive configs are stored in the event
900 // log, a check should be added here to only process audio
901 // streams. Tracking bug: webrtc:6399
902 for (auto& packet : packet_stream) {
903 if (packet.header.extension.hasAudioLevel) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800904 float x = ToCallTime(packet.timestamp);
ivocaac9d6f2016-09-22 07:01:47 -0700905 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
906 // Here we convert it to dBov.
907 float y = static_cast<float>(-packet.header.extension.audioLevel);
908 time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y));
909 }
910 }
911 }
912
913 for (auto& series : time_series) {
914 series.second.label = GetStreamName(series.first);
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100915 series.second.line_style = LineStyle::kLine;
philipel35ba9bd2017-04-19 05:58:51 -0700916 plot->AppendTimeSeries(std::move(series.second));
ivocaac9d6f2016-09-22 07:01:47 -0700917 }
918
919 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
ivocbf676632016-11-24 08:30:34 -0800920 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin,
ivocaac9d6f2016-09-22 07:01:47 -0700921 kTopMargin);
922 plot->SetTitle("Audio level");
923}
924
terelius54ce6802016-07-13 06:44:41 -0700925// For each SSRC, plot the time between the consecutive playouts.
926void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700927 for (auto& kv : rtp_packets_) {
928 StreamId stream_id = kv.first;
929 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
930 // Filter on direction and SSRC.
931 if (stream_id.GetDirection() != kIncomingPacket ||
932 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
933 continue;
terelius54ce6802016-07-13 06:44:41 -0700934 }
terelius54ce6802016-07-13 06:44:41 -0700935
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100936 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -0700937 ProcessPairs<LoggedRtpPacket, float>(
938 [](const LoggedRtpPacket& old_packet,
939 const LoggedRtpPacket& new_packet) {
940 int64_t diff =
941 WrappingDifference(new_packet.header.sequenceNumber,
942 old_packet.header.sequenceNumber, 1ul << 16);
Oskar Sundbom3928dbc2017-11-16 10:53:09 +0100943 return diff;
terelius53dc23c2017-03-13 05:24:05 -0700944 },
945 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700946 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700947 }
948
tereliusdc35dcd2016-08-01 12:03:27 -0700949 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
950 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
951 kTopMargin);
952 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700953}
954
Stefan Holmer99f8e082016-09-09 13:37:50 +0200955void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
956 for (auto& kv : rtp_packets_) {
957 StreamId stream_id = kv.first;
958 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
959 // Filter on direction and SSRC.
960 if (stream_id.GetDirection() != kIncomingPacket ||
terelius4c9b4af2017-01-30 08:44:51 -0800961 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
962 packet_stream.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200963 continue;
964 }
965
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +0100966 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kLine,
967 PointStyle::kHighlight);
Stefan Holmer99f8e082016-09-09 13:37:50 +0200968 const uint64_t kWindowUs = 1000000;
terelius4c9b4af2017-01-30 08:44:51 -0800969 const uint64_t kStep = 1000000;
Bjorn Terelius2eb31882017-11-30 15:15:25 +0100970 SeqNumUnwrapper<uint16_t> unwrapper_;
971 SeqNumUnwrapper<uint16_t> prior_unwrapper_;
terelius4c9b4af2017-01-30 08:44:51 -0800972 size_t window_index_begin = 0;
973 size_t window_index_end = 0;
974 int64_t highest_seq_number =
975 unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
976 int64_t highest_prior_seq_number =
977 prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
978
979 for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) {
980 while (window_index_end < packet_stream.size() &&
981 packet_stream[window_index_end].timestamp < t) {
982 int64_t sequence_number = unwrapper_.Unwrap(
983 packet_stream[window_index_end].header.sequenceNumber);
984 highest_seq_number = std::max(highest_seq_number, sequence_number);
985 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200986 }
terelius4c9b4af2017-01-30 08:44:51 -0800987 while (window_index_begin < packet_stream.size() &&
988 packet_stream[window_index_begin].timestamp < t - kWindowUs) {
989 int64_t sequence_number = prior_unwrapper_.Unwrap(
990 packet_stream[window_index_begin].header.sequenceNumber);
991 highest_prior_seq_number =
992 std::max(highest_prior_seq_number, sequence_number);
993 ++window_index_begin;
994 }
Qingsi Wang8eca1ff2018-02-02 11:49:44 -0800995 float x = ToCallTime(t);
terelius4c9b4af2017-01-30 08:44:51 -0800996 int64_t expected_packets = highest_seq_number - highest_prior_seq_number;
997 if (expected_packets > 0) {
998 int64_t received_packets = window_index_end - window_index_begin;
999 int64_t lost_packets = expected_packets - received_packets;
1000 float y = static_cast<float>(lost_packets) / expected_packets * 100;
1001 time_series.points.emplace_back(x, y);
1002 }
Stefan Holmer99f8e082016-09-09 13:37:50 +02001003 }
philipel35ba9bd2017-04-19 05:58:51 -07001004 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +02001005 }
1006
1007 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1008 plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin,
1009 kTopMargin);
1010 plot->SetTitle("Estimated incoming loss rate");
1011}
1012
terelius2ee076d2017-08-15 02:04:02 -07001013void EventLogAnalyzer::CreateIncomingDelayDeltaGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -07001014 for (auto& kv : rtp_packets_) {
1015 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -07001016 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -07001017 // Filter on direction and SSRC.
1018 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +02001019 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
1020 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
1021 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -07001022 continue;
1023 }
terelius54ce6802016-07-13 06:44:41 -07001024
terelius23c595a2017-03-15 01:59:12 -07001025 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001026 LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -07001027 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
1028 packet_stream, begin_time_,
1029 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -07001030 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -07001031
terelius23c595a2017-03-15 01:59:12 -07001032 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001033 LineStyle::kBar);
terelius53dc23c2017-03-13 05:24:05 -07001034 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
1035 packet_stream, begin_time_,
1036 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -07001037 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -07001038 }
1039
tereliusdc35dcd2016-08-01 12:03:27 -07001040 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1041 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
1042 kTopMargin);
terelius2ee076d2017-08-15 02:04:02 -07001043 plot->SetTitle("Network latency difference between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -07001044}
1045
terelius2ee076d2017-08-15 02:04:02 -07001046void EventLogAnalyzer::CreateIncomingDelayGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -07001047 for (auto& kv : rtp_packets_) {
1048 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -07001049 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -07001050 // Filter on direction and SSRC.
1051 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +02001052 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
1053 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
1054 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -07001055 continue;
1056 }
terelius54ce6802016-07-13 06:44:41 -07001057
terelius23c595a2017-03-15 01:59:12 -07001058 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001059 LineStyle::kLine);
terelius53dc23c2017-03-13 05:24:05 -07001060 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
1061 packet_stream, begin_time_,
1062 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -07001063 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -07001064
terelius23c595a2017-03-15 01:59:12 -07001065 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001066 LineStyle::kLine);
terelius53dc23c2017-03-13 05:24:05 -07001067 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
1068 packet_stream, begin_time_,
1069 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -07001070 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -07001071 }
1072
tereliusdc35dcd2016-08-01 12:03:27 -07001073 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1074 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
1075 kTopMargin);
terelius2ee076d2017-08-15 02:04:02 -07001076 plot->SetTitle("Network latency (relative to first packet)");
terelius54ce6802016-07-13 06:44:41 -07001077}
1078
tereliusf736d232016-08-04 10:00:11 -07001079// Plot the fraction of packets lost (as perceived by the loss-based BWE).
1080void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001081 TimeSeries time_series("Fraction lost", LineStyle::kLine,
1082 PointStyle::kHighlight);
tereliusf736d232016-08-04 10:00:11 -07001083 for (auto& bwe_update : bwe_loss_updates_) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001084 float x = ToCallTime(bwe_update.timestamp);
tereliusf736d232016-08-04 10:00:11 -07001085 float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -07001086 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -07001087 }
tereliusf736d232016-08-04 10:00:11 -07001088
Bjorn Terelius19f5be32017-10-18 12:39:49 +02001089 plot->AppendTimeSeries(std::move(time_series));
tereliusf736d232016-08-04 10:00:11 -07001090 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1091 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1092 kTopMargin);
1093 plot->SetTitle("Reported packet loss");
1094}
1095
terelius54ce6802016-07-13 06:44:41 -07001096// Plot the total bandwidth used by all RTP streams.
1097void EventLogAnalyzer::CreateTotalBitrateGraph(
1098 PacketDirection desired_direction,
philipel23c7f252017-07-14 06:30:03 -07001099 Plot* plot,
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001100 bool show_detector_state,
1101 bool show_alr_state) {
terelius54ce6802016-07-13 06:44:41 -07001102 struct TimestampSize {
1103 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
1104 uint64_t timestamp;
1105 size_t size;
1106 };
1107 std::vector<TimestampSize> packets;
1108
1109 PacketDirection direction;
1110 size_t total_length;
1111
1112 // Extract timestamps and sizes for the relevant packets.
1113 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
1114 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
1115 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
Elad Alon1d87b0e2017-10-03 15:01:03 +02001116 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, &total_length,
1117 nullptr);
terelius54ce6802016-07-13 06:44:41 -07001118 if (direction == desired_direction) {
1119 uint64_t timestamp = parsed_log_.GetTimestamp(i);
1120 packets.push_back(TimestampSize(timestamp, total_length));
1121 }
1122 }
1123 }
1124
1125 size_t window_index_begin = 0;
1126 size_t window_index_end = 0;
1127 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -07001128
1129 // Calculate a moving average of the bitrate and store in a TimeSeries.
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001130 TimeSeries bitrate_series("Bitrate", LineStyle::kLine);
terelius54ce6802016-07-13 06:44:41 -07001131 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
1132 while (window_index_end < packets.size() &&
1133 packets[window_index_end].timestamp < time) {
1134 bytes_in_window += packets[window_index_end].size;
terelius6addf492016-08-23 17:34:07 -07001135 ++window_index_end;
terelius54ce6802016-07-13 06:44:41 -07001136 }
1137 while (window_index_begin < packets.size() &&
1138 packets[window_index_begin].timestamp < time - window_duration_) {
1139 RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window);
1140 bytes_in_window -= packets[window_index_begin].size;
terelius6addf492016-08-23 17:34:07 -07001141 ++window_index_begin;
terelius54ce6802016-07-13 06:44:41 -07001142 }
1143 float window_duration_in_seconds =
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001144 static_cast<float>(window_duration_) / kNumMicrosecsPerSec;
1145 float x = ToCallTime(time);
terelius54ce6802016-07-13 06:44:41 -07001146 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001147 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -07001148 }
philipel35ba9bd2017-04-19 05:58:51 -07001149 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -07001150
terelius8058e582016-07-25 01:32:41 -07001151 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
1152 if (desired_direction == kOutgoingPacket) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001153 TimeSeries loss_series("Loss-based estimate", LineStyle::kStep);
philipel10fc0e62017-04-11 01:50:23 -07001154 for (auto& loss_update : bwe_loss_updates_) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001155 float x = ToCallTime(loss_update.timestamp);
philipel10fc0e62017-04-11 01:50:23 -07001156 float y = static_cast<float>(loss_update.new_bitrate) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001157 loss_series.points.emplace_back(x, y);
philipel10fc0e62017-04-11 01:50:23 -07001158 }
1159
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001160 TimeSeries delay_series("Delay-based estimate", LineStyle::kStep);
philipel23c7f252017-07-14 06:30:03 -07001161 IntervalSeries overusing_series("Overusing", "#ff8e82",
1162 IntervalSeries::kHorizontal);
1163 IntervalSeries underusing_series("Underusing", "#5092fc",
1164 IntervalSeries::kHorizontal);
1165 IntervalSeries normal_series("Normal", "#c4ffc4",
1166 IntervalSeries::kHorizontal);
1167 IntervalSeries* last_series = &normal_series;
1168 double last_detector_switch = 0.0;
1169
1170 BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal;
1171
philipel10fc0e62017-04-11 01:50:23 -07001172 for (auto& delay_update : bwe_delay_updates_) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001173 float x = ToCallTime(delay_update.timestamp);
philipel10fc0e62017-04-11 01:50:23 -07001174 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel23c7f252017-07-14 06:30:03 -07001175
1176 if (last_detector_state != delay_update.detector_state) {
1177 last_series->intervals.emplace_back(last_detector_switch, x);
1178 last_detector_state = delay_update.detector_state;
1179 last_detector_switch = x;
1180
1181 switch (delay_update.detector_state) {
1182 case BandwidthUsage::kBwNormal:
1183 last_series = &normal_series;
1184 break;
1185 case BandwidthUsage::kBwUnderusing:
1186 last_series = &underusing_series;
1187 break;
1188 case BandwidthUsage::kBwOverusing:
1189 last_series = &overusing_series;
1190 break;
Elad Alon1d87b0e2017-10-03 15:01:03 +02001191 case BandwidthUsage::kLast:
1192 RTC_NOTREACHED();
philipel23c7f252017-07-14 06:30:03 -07001193 }
1194 }
1195
philipel35ba9bd2017-04-19 05:58:51 -07001196 delay_series.points.emplace_back(x, y);
terelius8058e582016-07-25 01:32:41 -07001197 }
philipele127e7a2017-03-29 16:28:53 +02001198
philipel23c7f252017-07-14 06:30:03 -07001199 RTC_CHECK(last_series);
1200 last_series->intervals.emplace_back(last_detector_switch, end_time_);
1201
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001202 TimeSeries created_series("Probe cluster created.", LineStyle::kNone,
1203 PointStyle::kHighlight);
philipele127e7a2017-03-29 16:28:53 +02001204 for (auto& cluster : bwe_probe_cluster_created_events_) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001205 float x = ToCallTime(cluster.timestamp);
philipele127e7a2017-03-29 16:28:53 +02001206 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001207 created_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +02001208 }
1209
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001210 TimeSeries result_series("Probing results.", LineStyle::kNone,
1211 PointStyle::kHighlight);
philipele127e7a2017-03-29 16:28:53 +02001212 for (auto& result : bwe_probe_result_events_) {
1213 if (result.bitrate_bps) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001214 float x = ToCallTime(result.timestamp);
philipele127e7a2017-03-29 16:28:53 +02001215 float y = static_cast<float>(*result.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001216 result_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +02001217 }
1218 }
philipel23c7f252017-07-14 06:30:03 -07001219
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001220 IntervalSeries alr_state("ALR", "#555555", IntervalSeries::kHorizontal);
1221 bool previously_in_alr = false;
1222 int64_t alr_start = 0;
1223 for (auto& alr : alr_state_events_) {
1224 float y = ToCallTime(alr.timestamp);
1225 if (!previously_in_alr && alr.in_alr) {
1226 alr_start = alr.timestamp;
1227 previously_in_alr = true;
1228 } else if (previously_in_alr && !alr.in_alr) {
1229 float x = ToCallTime(alr_start);
1230 alr_state.intervals.emplace_back(x, y);
1231 previously_in_alr = false;
1232 }
1233 }
1234
1235 if (previously_in_alr) {
1236 float x = ToCallTime(alr_start);
1237 float y = ToCallTime(end_time_);
1238 alr_state.intervals.emplace_back(x, y);
1239 }
1240
philipel23c7f252017-07-14 06:30:03 -07001241 if (show_detector_state) {
1242 plot->AppendIntervalSeries(std::move(overusing_series));
1243 plot->AppendIntervalSeries(std::move(underusing_series));
1244 plot->AppendIntervalSeries(std::move(normal_series));
1245 }
1246
Ilya Nikolaevskiya4259f62017-12-05 13:19:45 +01001247 if (show_alr_state) {
1248 plot->AppendIntervalSeries(std::move(alr_state));
1249 }
philipel35ba9bd2017-04-19 05:58:51 -07001250 plot->AppendTimeSeries(std::move(loss_series));
1251 plot->AppendTimeSeries(std::move(delay_series));
1252 plot->AppendTimeSeries(std::move(created_series));
1253 plot->AppendTimeSeries(std::move(result_series));
terelius8058e582016-07-25 01:32:41 -07001254 }
philipele127e7a2017-03-29 16:28:53 +02001255
terelius2c8e8a32017-06-02 01:29:48 -07001256 // Overlay the incoming REMB over the outgoing bitrate
1257 // and outgoing REMB over incoming bitrate.
1258 PacketDirection remb_direction =
1259 desired_direction == kOutgoingPacket ? kIncomingPacket : kOutgoingPacket;
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001260 TimeSeries remb_series("Remb", LineStyle::kStep);
terelius2c8e8a32017-06-02 01:29:48 -07001261 std::multimap<uint64_t, const LoggedRtcpPacket*> remb_packets;
1262 for (const auto& kv : rtcp_packets_) {
1263 if (kv.first.GetDirection() == remb_direction) {
1264 for (const LoggedRtcpPacket& rtcp_packet : kv.second) {
1265 if (rtcp_packet.type == kRtcpRemb) {
1266 remb_packets.insert(
1267 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1268 }
1269 }
1270 }
1271 }
1272
1273 for (const auto& kv : remb_packets) {
1274 const LoggedRtcpPacket* const rtcp = kv.second;
1275 const rtcp::Remb* const remb = static_cast<rtcp::Remb*>(rtcp->packet.get());
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001276 float x = ToCallTime(rtcp->timestamp);
terelius2c8e8a32017-06-02 01:29:48 -07001277 float y = static_cast<float>(remb->bitrate_bps()) / 1000;
1278 remb_series.points.emplace_back(x, y);
1279 }
1280 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1281
tereliusdc35dcd2016-08-01 12:03:27 -07001282 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1283 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001284 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001285 plot->SetTitle("Incoming RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001286 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001287 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001288 }
1289}
1290
1291// For each SSRC, plot the bandwidth used by that stream.
1292void EventLogAnalyzer::CreateStreamBitrateGraph(
1293 PacketDirection desired_direction,
1294 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -07001295 for (auto& kv : rtp_packets_) {
1296 StreamId stream_id = kv.first;
1297 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
1298 // Filter on direction and SSRC.
1299 if (stream_id.GetDirection() != desired_direction ||
1300 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
1301 continue;
terelius54ce6802016-07-13 06:44:41 -07001302 }
1303
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001304 TimeSeries time_series(GetStreamName(stream_id), LineStyle::kLine);
terelius53dc23c2017-03-13 05:24:05 -07001305 MovingAverage<LoggedRtpPacket, double>(
1306 [](const LoggedRtpPacket& packet) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001307 return packet.total_length * 8.0 / 1000.0;
terelius53dc23c2017-03-13 05:24:05 -07001308 },
1309 packet_stream, begin_time_, end_time_, window_duration_, step_,
1310 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001311 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001312 }
1313
tereliusdc35dcd2016-08-01 12:03:27 -07001314 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1315 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001316 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001317 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001318 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001319 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001320 }
1321}
1322
Bjorn Terelius28db2662017-10-04 14:22:43 +02001323void EventLogAnalyzer::CreateSendSideBweSimulationGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001324 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1325 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
Stefan Holmer13181032016-07-29 14:48:54 +02001326
1327 for (const auto& kv : rtp_packets_) {
1328 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1329 for (const LoggedRtpPacket& rtp_packet : kv.second)
1330 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1331 }
1332 }
1333
1334 for (const auto& kv : rtcp_packets_) {
1335 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1336 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1337 incoming_rtcp.insert(
1338 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1339 }
1340 }
1341
1342 SimulatedClock clock(0);
1343 BitrateObserver observer;
1344 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001345 PacketRouter packet_router;
Stefan Holmer5c8942a2017-08-22 16:16:44 +02001346 PacedSender pacer(&clock, &packet_router, &null_event_log);
1347 SendSideCongestionController cc(&clock, &observer, &null_event_log, &pacer);
Stefan Holmer13181032016-07-29 14:48:54 +02001348 // TODO(holmer): Log the call config and use that here instead.
1349 static const uint32_t kDefaultStartBitrateBps = 300000;
1350 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1351
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001352 TimeSeries time_series("Delay-based estimate", LineStyle::kStep,
1353 PointStyle::kHighlight);
1354 TimeSeries acked_time_series("Acked bitrate", LineStyle::kLine,
1355 PointStyle::kHighlight);
1356 TimeSeries acked_estimate_time_series(
1357 "Acked bitrate estimate", LineStyle::kLine, PointStyle::kHighlight);
Stefan Holmer13181032016-07-29 14:48:54 +02001358
1359 auto rtp_iterator = outgoing_rtp.begin();
1360 auto rtcp_iterator = incoming_rtcp.begin();
1361
1362 auto NextRtpTime = [&]() {
1363 if (rtp_iterator != outgoing_rtp.end())
1364 return static_cast<int64_t>(rtp_iterator->first);
1365 return std::numeric_limits<int64_t>::max();
1366 };
1367
1368 auto NextRtcpTime = [&]() {
1369 if (rtcp_iterator != incoming_rtcp.end())
1370 return static_cast<int64_t>(rtcp_iterator->first);
1371 return std::numeric_limits<int64_t>::max();
1372 };
1373
1374 auto NextProcessTime = [&]() {
1375 if (rtcp_iterator != incoming_rtcp.end() ||
1376 rtp_iterator != outgoing_rtp.end()) {
1377 return clock.TimeInMicroseconds() +
1378 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
1379 }
1380 return std::numeric_limits<int64_t>::max();
1381 };
1382
Stefan Holmer492ee282016-10-27 17:19:20 +02001383 RateStatistics acked_bitrate(250, 8000);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001384#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1385 // The event_log_visualizer should normally not be compiled with
1386 // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE since the normal plots won't work.
1387 // However, compiling with BWE_TEST_LOGGING, runnning with --plot_sendside_bwe
1388 // and piping the output to plot_dynamics.py can be used as a hack to get the
1389 // internal state of various BWE components. In this case, it is important
1390 // we don't instantiate the AcknowledgedBitrateEstimator both here and in
1391 // SendSideCongestionController since that would lead to duplicate outputs.
1392 AcknowledgedBitrateEstimator acknowledged_bitrate_estimator(
1393 rtc::MakeUnique<BitrateEstimator>());
1394#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001395 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
Stefan Holmer492ee282016-10-27 17:19:20 +02001396 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001397 while (time_us != std::numeric_limits<int64_t>::max()) {
1398 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1399 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001400 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001401 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1402 if (rtcp.type == kRtcpTransportFeedback) {
elad.alon5bbf43f2017-03-09 06:40:08 -08001403 cc.OnTransportFeedback(
1404 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
1405 std::vector<PacketFeedback> feedback = cc.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001406 SortPacketFeedbackVector(&feedback);
Stefan Holmer60e43462016-09-07 09:58:20 +02001407 rtc::Optional<uint32_t> bitrate_bps;
1408 if (!feedback.empty()) {
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001409#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1410 acknowledged_bitrate_estimator.IncomingPacketFeedbackVector(feedback);
1411#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
elad.alonf9490002017-03-06 05:32:21 -08001412 for (const PacketFeedback& packet : feedback)
Stefan Holmer60e43462016-09-07 09:58:20 +02001413 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1414 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1415 }
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001416 float x = ToCallTime(clock.TimeInMicroseconds());
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001417 float y = bitrate_bps.value_or(0) / 1000;
Stefan Holmer60e43462016-09-07 09:58:20 +02001418 acked_time_series.points.emplace_back(x, y);
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001419#if !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
1420 y = acknowledged_bitrate_estimator.bitrate_bps().value_or(0) / 1000;
1421 acked_estimate_time_series.points.emplace_back(x, y);
1422#endif // !(BWE_TEST_LOGGING_COMPILE_TIME_ENABLE)
Stefan Holmer13181032016-07-29 14:48:54 +02001423 }
1424 ++rtcp_iterator;
1425 }
1426 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001427 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001428 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1429 if (rtp.header.extension.hasTransportSequenceNumber) {
1430 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001431 cc.AddPacket(rtp.header.ssrc,
1432 rtp.header.extension.transportSequenceNumber,
elad.alon5bbf43f2017-03-09 06:40:08 -08001433 rtp.total_length, PacedPacketInfo());
Stefan Holmer13181032016-07-29 14:48:54 +02001434 rtc::SentPacket sent_packet(
1435 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1436 cc.OnSentPacket(sent_packet);
1437 }
1438 ++rtp_iterator;
1439 }
stefanc3de0332016-08-02 07:22:17 -07001440 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1441 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001442 cc.Process();
stefanc3de0332016-08-02 07:22:17 -07001443 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001444 if (observer.GetAndResetBitrateUpdated() ||
1445 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001446 uint32_t y = observer.last_bitrate_bps() / 1000;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001447 float x = ToCallTime(clock.TimeInMicroseconds());
Stefan Holmer13181032016-07-29 14:48:54 +02001448 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001449 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001450 }
1451 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1452 }
1453 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001454 plot->AppendTimeSeries(std::move(time_series));
1455 plot->AppendTimeSeries(std::move(acked_time_series));
Bjorn Terelius6984ad22017-10-24 12:19:45 +02001456 plot->AppendTimeSeriesIfNotEmpty(std::move(acked_estimate_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001457
tereliusdc35dcd2016-08-01 12:03:27 -07001458 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1459 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001460 plot->SetTitle("Simulated send-side BWE behavior");
1461}
1462
1463void EventLogAnalyzer::CreateReceiveSideBweSimulationGraph(Plot* plot) {
1464 class RembInterceptingPacketRouter : public PacketRouter {
1465 public:
1466 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
1467 uint32_t bitrate_bps) override {
1468 last_bitrate_bps_ = bitrate_bps;
1469 bitrate_updated_ = true;
1470 PacketRouter::OnReceiveBitrateChanged(ssrcs, bitrate_bps);
1471 }
1472 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
1473 bool GetAndResetBitrateUpdated() {
1474 bool bitrate_updated = bitrate_updated_;
1475 bitrate_updated_ = false;
1476 return bitrate_updated;
1477 }
1478
1479 private:
1480 uint32_t last_bitrate_bps_;
1481 bool bitrate_updated_;
1482 };
1483
1484 std::multimap<uint64_t, const LoggedRtpPacket*> incoming_rtp;
1485
1486 for (const auto& kv : rtp_packets_) {
1487 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket &&
1488 IsVideoSsrc(kv.first)) {
1489 for (const LoggedRtpPacket& rtp_packet : kv.second)
1490 incoming_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1491 }
1492 }
1493
1494 SimulatedClock clock(0);
1495 RembInterceptingPacketRouter packet_router;
1496 // TODO(terelius): The PacketRrouter is the used as the RemoteBitrateObserver.
1497 // Is this intentional?
1498 ReceiveSideCongestionController rscc(&clock, &packet_router);
1499 // TODO(holmer): Log the call config and use that here instead.
1500 // static const uint32_t kDefaultStartBitrateBps = 300000;
1501 // rscc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1502
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001503 TimeSeries time_series("Receive side estimate", LineStyle::kLine,
1504 PointStyle::kHighlight);
1505 TimeSeries acked_time_series("Received bitrate", LineStyle::kLine);
Bjorn Terelius28db2662017-10-04 14:22:43 +02001506
1507 RateStatistics acked_bitrate(250, 8000);
1508 int64_t last_update_us = 0;
1509 for (const auto& kv : incoming_rtp) {
1510 const LoggedRtpPacket& packet = *kv.second;
1511 int64_t arrival_time_ms = packet.timestamp / 1000;
1512 size_t payload = packet.total_length; /*Should subtract header?*/
1513 clock.AdvanceTimeMicroseconds(packet.timestamp -
1514 clock.TimeInMicroseconds());
1515 rscc.OnReceivedPacket(arrival_time_ms, payload, packet.header);
1516 acked_bitrate.Update(payload, arrival_time_ms);
1517 rtc::Optional<uint32_t> bitrate_bps = acked_bitrate.Rate(arrival_time_ms);
1518 if (bitrate_bps) {
1519 uint32_t y = *bitrate_bps / 1000;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001520 float x = ToCallTime(clock.TimeInMicroseconds());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001521 acked_time_series.points.emplace_back(x, y);
1522 }
1523 if (packet_router.GetAndResetBitrateUpdated() ||
1524 clock.TimeInMicroseconds() - last_update_us >= 1e6) {
1525 uint32_t y = packet_router.last_bitrate_bps() / 1000;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001526 float x = ToCallTime(clock.TimeInMicroseconds());
Bjorn Terelius28db2662017-10-04 14:22:43 +02001527 time_series.points.emplace_back(x, y);
1528 last_update_us = clock.TimeInMicroseconds();
1529 }
1530 }
1531 // Add the data set to the plot.
1532 plot->AppendTimeSeries(std::move(time_series));
1533 plot->AppendTimeSeries(std::move(acked_time_series));
1534
1535 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1536 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1537 plot->SetTitle("Simulated receive-side BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001538}
1539
tereliuse34c19c2016-08-15 08:47:14 -07001540void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001541 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1542 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
stefanc3de0332016-08-02 07:22:17 -07001543
1544 for (const auto& kv : rtp_packets_) {
1545 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1546 for (const LoggedRtpPacket& rtp_packet : kv.second)
1547 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1548 }
1549 }
1550
1551 for (const auto& kv : rtcp_packets_) {
1552 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1553 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1554 incoming_rtcp.insert(
1555 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1556 }
1557 }
1558
1559 SimulatedClock clock(0);
elad.alon5bbf43f2017-03-09 06:40:08 -08001560 TransportFeedbackAdapter feedback_adapter(&clock);
stefanc3de0332016-08-02 07:22:17 -07001561
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001562 TimeSeries late_feedback_series("Late feedback results.", LineStyle::kNone,
1563 PointStyle::kHighlight);
1564 TimeSeries time_series("Network Delay Change", LineStyle::kLine,
1565 PointStyle::kHighlight);
stefanc3de0332016-08-02 07:22:17 -07001566 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
1567
1568 auto rtp_iterator = outgoing_rtp.begin();
1569 auto rtcp_iterator = incoming_rtcp.begin();
1570
1571 auto NextRtpTime = [&]() {
1572 if (rtp_iterator != outgoing_rtp.end())
1573 return static_cast<int64_t>(rtp_iterator->first);
1574 return std::numeric_limits<int64_t>::max();
1575 };
1576
1577 auto NextRtcpTime = [&]() {
1578 if (rtcp_iterator != incoming_rtcp.end())
1579 return static_cast<int64_t>(rtcp_iterator->first);
1580 return std::numeric_limits<int64_t>::max();
1581 };
1582
1583 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
stefana0a8ed72017-09-06 02:06:32 -07001584 int64_t prev_y = 0;
stefanc3de0332016-08-02 07:22:17 -07001585 while (time_us != std::numeric_limits<int64_t>::max()) {
1586 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1587 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
1588 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
1589 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1590 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001591 feedback_adapter.OnTransportFeedback(
1592 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
elad.alonf9490002017-03-06 05:32:21 -08001593 std::vector<PacketFeedback> feedback =
1594 feedback_adapter.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001595 SortPacketFeedbackVector(&feedback);
elad.alonf9490002017-03-06 05:32:21 -08001596 for (const PacketFeedback& packet : feedback) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001597 float x = ToCallTime(clock.TimeInMicroseconds());
srtee0572e52017-11-30 09:59:33 +01001598 if (packet.send_time_ms == PacketFeedback::kNoSendTime) {
stefana0a8ed72017-09-06 02:06:32 -07001599 late_feedback_series.points.emplace_back(x, prev_y);
1600 continue;
1601 }
1602 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1603 prev_y = y;
stefanc3de0332016-08-02 07:22:17 -07001604 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
1605 time_series.points.emplace_back(x, y);
1606 }
1607 }
1608 ++rtcp_iterator;
1609 }
1610 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1611 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1612 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1613 if (rtp.header.extension.hasTransportSequenceNumber) {
1614 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001615 feedback_adapter.AddPacket(rtp.header.ssrc,
1616 rtp.header.extension.transportSequenceNumber,
philipel8aadd502017-02-23 02:56:13 -08001617 rtp.total_length, PacedPacketInfo());
stefanc3de0332016-08-02 07:22:17 -07001618 feedback_adapter.OnSentPacket(
1619 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1620 }
1621 ++rtp_iterator;
1622 }
1623 time_us = std::min(NextRtpTime(), NextRtcpTime());
1624 }
1625 // We assume that the base network delay (w/o queues) is the min delay
1626 // observed during the call.
1627 for (TimeSeriesPoint& point : time_series.points)
1628 point.y -= estimated_base_delay_ms;
stefana0a8ed72017-09-06 02:06:32 -07001629 for (TimeSeriesPoint& point : late_feedback_series.points)
1630 point.y -= estimated_base_delay_ms;
stefanc3de0332016-08-02 07:22:17 -07001631 // Add the data set to the plot.
stefana0a8ed72017-09-06 02:06:32 -07001632 plot->AppendTimeSeriesIfNotEmpty(std::move(time_series));
1633 plot->AppendTimeSeriesIfNotEmpty(std::move(late_feedback_series));
stefanc3de0332016-08-02 07:22:17 -07001634
1635 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1636 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1637 plot->SetTitle("Network Delay Change.");
1638}
stefan08383272016-12-20 08:51:52 -08001639
1640std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps()
1641 const {
1642 std::vector<std::pair<int64_t, int64_t>> timestamps;
1643 size_t largest_stream_size = 0;
1644 const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr;
1645 // Find the incoming video stream with the most number of packets that is
1646 // not rtx.
1647 for (const auto& kv : rtp_packets_) {
1648 if (kv.first.GetDirection() == kIncomingPacket &&
1649 video_ssrcs_.find(kv.first) != video_ssrcs_.end() &&
1650 rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() &&
1651 kv.second.size() > largest_stream_size) {
1652 largest_stream_size = kv.second.size();
1653 largest_video_stream = &kv.second;
1654 }
1655 }
1656 if (largest_video_stream == nullptr) {
1657 for (auto& packet : *largest_video_stream) {
1658 if (packet.header.markerBit) {
1659 int64_t capture_ms = packet.header.timestamp / 90.0;
1660 int64_t arrival_ms = packet.timestamp / 1000.0;
1661 timestamps.push_back(std::make_pair(capture_ms, arrival_ms));
1662 }
1663 }
1664 }
1665 return timestamps;
1666}
stefane372d3c2017-02-02 08:04:18 -08001667
Bjorn Terelius0295a962017-10-25 17:42:41 +02001668void EventLogAnalyzer::CreatePacerDelayGraph(Plot* plot) {
1669 for (const auto& kv : rtp_packets_) {
1670 const std::vector<LoggedRtpPacket>& packets = kv.second;
1671 StreamId stream_id = kv.first;
Bjorn Tereliusb87c27e2017-11-09 11:55:51 +01001672 if (stream_id.GetDirection() == kIncomingPacket)
1673 continue;
Bjorn Terelius0295a962017-10-25 17:42:41 +02001674
1675 if (packets.size() < 2) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001676 RTC_LOG(LS_WARNING)
1677 << "Can't estimate a the RTP clock frequency or the "
1678 "pacer delay with less than 2 packets in the stream";
Bjorn Terelius0295a962017-10-25 17:42:41 +02001679 continue;
1680 }
1681 rtc::Optional<uint32_t> estimated_frequency =
1682 EstimateRtpClockFrequency(packets);
1683 if (!estimated_frequency)
1684 continue;
1685 if (IsVideoSsrc(stream_id) && *estimated_frequency != 90000) {
Mirko Bonadei675513b2017-11-09 11:09:25 +01001686 RTC_LOG(LS_WARNING)
Bjorn Terelius0295a962017-10-25 17:42:41 +02001687 << "Video stream should use a 90 kHz clock but appears to use "
1688 << *estimated_frequency / 1000 << ". Discarding.";
1689 continue;
1690 }
1691
1692 TimeSeries pacer_delay_series(
1693 GetStreamName(stream_id) + "(" +
1694 std::to_string(*estimated_frequency / 1000) + " kHz)",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001695 LineStyle::kLine, PointStyle::kHighlight);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001696 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
1697 uint64_t first_capture_timestamp =
1698 timestamp_unwrapper.Unwrap(packets.front().header.timestamp);
1699 uint64_t first_send_timestamp = packets.front().timestamp;
1700 for (LoggedRtpPacket packet : packets) {
1701 double capture_time_ms = (static_cast<double>(timestamp_unwrapper.Unwrap(
1702 packet.header.timestamp)) -
1703 first_capture_timestamp) /
1704 *estimated_frequency * 1000;
1705 double send_time_ms =
1706 static_cast<double>(packet.timestamp - first_send_timestamp) / 1000;
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001707 float x = ToCallTime(packet.timestamp);
Bjorn Terelius0295a962017-10-25 17:42:41 +02001708 float y = send_time_ms - capture_time_ms;
1709 pacer_delay_series.points.emplace_back(x, y);
1710 }
1711 plot->AppendTimeSeries(std::move(pacer_delay_series));
1712 }
1713
1714 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1715 plot->SetSuggestedYAxis(0, 10, "Pacer delay (ms)", kBottomMargin, kTopMargin);
1716 plot->SetTitle(
1717 "Delay from capture to send time. (First packet normalized to 0.)");
1718}
1719
stefane372d3c2017-02-02 08:04:18 -08001720void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) {
1721 for (const auto& kv : rtp_packets_) {
1722 const std::vector<LoggedRtpPacket>& rtp_packets = kv.second;
1723 StreamId stream_id = kv.first;
1724
1725 {
terelius23c595a2017-03-15 01:59:12 -07001726 TimeSeries timestamp_data(GetStreamName(stream_id) + " capture-time",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001727 LineStyle::kLine, PointStyle::kHighlight);
stefane372d3c2017-02-02 08:04:18 -08001728 for (LoggedRtpPacket packet : rtp_packets) {
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001729 float x = ToCallTime(packet.timestamp);
stefane372d3c2017-02-02 08:04:18 -08001730 float y = packet.header.timestamp;
1731 timestamp_data.points.emplace_back(x, y);
1732 }
philipel35ba9bd2017-04-19 05:58:51 -07001733 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001734 }
1735
1736 {
1737 auto kv = rtcp_packets_.find(stream_id);
1738 if (kv != rtcp_packets_.end()) {
1739 const auto& packets = kv->second;
terelius23c595a2017-03-15 01:59:12 -07001740 TimeSeries timestamp_data(
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001741 GetStreamName(stream_id) + " rtcp capture-time", LineStyle::kLine,
1742 PointStyle::kHighlight);
stefane372d3c2017-02-02 08:04:18 -08001743 for (const LoggedRtcpPacket& rtcp : packets) {
1744 if (rtcp.type != kRtcpSr)
1745 continue;
1746 rtcp::SenderReport* sr;
1747 sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get());
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08001748 float x = ToCallTime(rtcp.timestamp);
stefane372d3c2017-02-02 08:04:18 -08001749 float y = sr->rtp_timestamp();
1750 timestamp_data.points.emplace_back(x, y);
1751 }
philipel35ba9bd2017-04-19 05:58:51 -07001752 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001753 }
1754 }
1755 }
1756
1757 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1758 plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin);
1759 plot->SetTitle("Timestamps");
1760}
michaelt6e5b2192017-02-22 07:33:27 -08001761
1762void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001763 TimeSeries time_series("Audio encoder target bitrate", LineStyle::kLine,
1764 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001765 ProcessPoints<AudioNetworkAdaptationEvent>(
1766 [](const AudioNetworkAdaptationEvent& ana_event) -> rtc::Optional<float> {
michaelt6e5b2192017-02-22 07:33:27 -08001767 if (ana_event.config.bitrate_bps)
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001768 return static_cast<float>(*ana_event.config.bitrate_bps);
1769 return rtc::nullopt;
terelius53dc23c2017-03-13 05:24:05 -07001770 },
philipel35ba9bd2017-04-19 05:58:51 -07001771 audio_network_adaptation_events_, begin_time_, &time_series);
1772 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001773 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1774 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1775 plot->SetTitle("Reported audio encoder target bitrate");
1776}
1777
1778void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001779 TimeSeries time_series("Audio encoder frame length", LineStyle::kLine,
1780 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001781 ProcessPoints<AudioNetworkAdaptationEvent>(
1782 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001783 if (ana_event.config.frame_length_ms)
1784 return rtc::Optional<float>(
1785 static_cast<float>(*ana_event.config.frame_length_ms));
1786 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001787 },
philipel35ba9bd2017-04-19 05:58:51 -07001788 audio_network_adaptation_events_, begin_time_, &time_series);
1789 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001790 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1791 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1792 plot->SetTitle("Reported audio encoder frame length");
1793}
1794
terelius2ee076d2017-08-15 02:04:02 -07001795void EventLogAnalyzer::CreateAudioEncoderPacketLossGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001796 TimeSeries time_series("Audio encoder uplink packet loss fraction",
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001797 LineStyle::kLine, PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001798 ProcessPoints<AudioNetworkAdaptationEvent>(
1799 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001800 if (ana_event.config.uplink_packet_loss_fraction)
1801 return rtc::Optional<float>(static_cast<float>(
1802 *ana_event.config.uplink_packet_loss_fraction));
1803 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001804 },
philipel35ba9bd2017-04-19 05:58:51 -07001805 audio_network_adaptation_events_, begin_time_, &time_series);
1806 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001807 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1808 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1809 kTopMargin);
1810 plot->SetTitle("Reported audio encoder lost packets");
1811}
1812
1813void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001814 TimeSeries time_series("Audio encoder FEC", LineStyle::kLine,
1815 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001816 ProcessPoints<AudioNetworkAdaptationEvent>(
1817 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001818 if (ana_event.config.enable_fec)
1819 return rtc::Optional<float>(
1820 static_cast<float>(*ana_event.config.enable_fec));
1821 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001822 },
philipel35ba9bd2017-04-19 05:58:51 -07001823 audio_network_adaptation_events_, begin_time_, &time_series);
1824 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001825 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1826 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1827 plot->SetTitle("Reported audio encoder FEC");
1828}
1829
1830void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001831 TimeSeries time_series("Audio encoder DTX", LineStyle::kLine,
1832 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001833 ProcessPoints<AudioNetworkAdaptationEvent>(
1834 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001835 if (ana_event.config.enable_dtx)
1836 return rtc::Optional<float>(
1837 static_cast<float>(*ana_event.config.enable_dtx));
1838 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001839 },
philipel35ba9bd2017-04-19 05:58:51 -07001840 audio_network_adaptation_events_, begin_time_, &time_series);
1841 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001842 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1843 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1844 plot->SetTitle("Reported audio encoder DTX");
1845}
1846
1847void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01001848 TimeSeries time_series("Audio encoder number of channels", LineStyle::kLine,
1849 PointStyle::kHighlight);
terelius53dc23c2017-03-13 05:24:05 -07001850 ProcessPoints<AudioNetworkAdaptationEvent>(
1851 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001852 if (ana_event.config.num_channels)
1853 return rtc::Optional<float>(
1854 static_cast<float>(*ana_event.config.num_channels));
1855 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001856 },
philipel35ba9bd2017-04-19 05:58:51 -07001857 audio_network_adaptation_events_, begin_time_, &time_series);
1858 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001859 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1860 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1861 kBottomMargin, kTopMargin);
1862 plot->SetTitle("Reported audio encoder number of channels");
1863}
henrik.lundin3c938fc2017-06-14 06:09:58 -07001864
1865class NetEqStreamInput : public test::NetEqInput {
1866 public:
1867 // Does not take any ownership, and all pointers must refer to valid objects
1868 // that outlive the one constructed.
1869 NetEqStreamInput(const std::vector<LoggedRtpPacket>* packet_stream,
1870 const std::vector<uint64_t>* output_events_us,
1871 rtc::Optional<uint64_t> end_time_us)
1872 : packet_stream_(*packet_stream),
1873 packet_stream_it_(packet_stream_.begin()),
1874 output_events_us_it_(output_events_us->begin()),
1875 output_events_us_end_(output_events_us->end()),
1876 end_time_us_(end_time_us) {
1877 RTC_DCHECK(packet_stream);
1878 RTC_DCHECK(output_events_us);
1879 }
1880
1881 rtc::Optional<int64_t> NextPacketTime() const override {
1882 if (packet_stream_it_ == packet_stream_.end()) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001883 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001884 }
1885 if (end_time_us_ && packet_stream_it_->timestamp > *end_time_us_) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001886 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001887 }
1888 // Convert from us to ms.
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001889 return packet_stream_it_->timestamp / 1000;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001890 }
1891
1892 rtc::Optional<int64_t> NextOutputEventTime() const override {
1893 if (output_events_us_it_ == output_events_us_end_) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001894 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001895 }
1896 if (end_time_us_ && *output_events_us_it_ > *end_time_us_) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001897 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001898 }
1899 // Convert from us to ms.
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001900 return rtc::checked_cast<int64_t>(*output_events_us_it_ / 1000);
henrik.lundin3c938fc2017-06-14 06:09:58 -07001901 }
1902
1903 std::unique_ptr<PacketData> PopPacket() override {
1904 if (packet_stream_it_ == packet_stream_.end()) {
1905 return std::unique_ptr<PacketData>();
1906 }
1907 std::unique_ptr<PacketData> packet_data(new PacketData());
1908 packet_data->header = packet_stream_it_->header;
1909 // Convert from us to ms.
1910 packet_data->time_ms = packet_stream_it_->timestamp / 1000.0;
1911
1912 // This is a header-only "dummy" packet. Set the payload to all zeros, with
1913 // length according to the virtual length.
1914 packet_data->payload.SetSize(packet_stream_it_->total_length);
1915 std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0);
1916
1917 ++packet_stream_it_;
1918 return packet_data;
1919 }
1920
1921 void AdvanceOutputEvent() override {
1922 if (output_events_us_it_ != output_events_us_end_) {
1923 ++output_events_us_it_;
1924 }
1925 }
1926
1927 bool ended() const override { return !NextEventTime(); }
1928
1929 rtc::Optional<RTPHeader> NextHeader() const override {
1930 if (packet_stream_it_ == packet_stream_.end()) {
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001931 return rtc::nullopt;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001932 }
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01001933 return packet_stream_it_->header;
henrik.lundin3c938fc2017-06-14 06:09:58 -07001934 }
1935
1936 private:
1937 const std::vector<LoggedRtpPacket>& packet_stream_;
1938 std::vector<LoggedRtpPacket>::const_iterator packet_stream_it_;
1939 std::vector<uint64_t>::const_iterator output_events_us_it_;
1940 const std::vector<uint64_t>::const_iterator output_events_us_end_;
1941 const rtc::Optional<uint64_t> end_time_us_;
1942};
1943
1944namespace {
1945// Creates a NetEq test object and all necessary input and output helpers. Runs
1946// the test and returns the NetEqDelayAnalyzer object that was used to
1947// instrument the test.
1948std::unique_ptr<test::NetEqDelayAnalyzer> CreateNetEqTestAndRun(
1949 const std::vector<LoggedRtpPacket>* packet_stream,
1950 const std::vector<uint64_t>* output_events_us,
1951 rtc::Optional<uint64_t> end_time_us,
1952 const std::string& replacement_file_name,
1953 int file_sample_rate_hz) {
1954 std::unique_ptr<test::NetEqInput> input(
1955 new NetEqStreamInput(packet_stream, output_events_us, end_time_us));
1956
1957 constexpr int kReplacementPt = 127;
1958 std::set<uint8_t> cn_types;
1959 std::set<uint8_t> forbidden_types;
1960 input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt,
1961 cn_types, forbidden_types));
1962
1963 NetEq::Config config;
1964 config.max_packets_in_buffer = 200;
1965 config.enable_fast_accelerate = true;
1966
1967 std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink());
1968
1969 test::NetEqTest::DecoderMap codecs;
1970
1971 // Create a "replacement decoder" that produces the decoded audio by reading
1972 // from a file rather than from the encoded payloads.
1973 std::unique_ptr<test::ResampleInputAudioFile> replacement_file(
1974 new test::ResampleInputAudioFile(replacement_file_name,
1975 file_sample_rate_hz));
1976 replacement_file->set_output_rate_hz(48000);
1977 std::unique_ptr<AudioDecoder> replacement_decoder(
1978 new test::FakeDecodeFromFile(std::move(replacement_file), 48000, false));
1979 test::NetEqTest::ExtDecoderMap ext_codecs;
1980 ext_codecs[kReplacementPt] = {replacement_decoder.get(),
1981 NetEqDecoder::kDecoderArbitrary,
1982 "replacement codec"};
1983
1984 std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb(
1985 new test::NetEqDelayAnalyzer);
1986 test::DefaultNetEqTestErrorCallback error_cb;
1987 test::NetEqTest::Callbacks callbacks;
1988 callbacks.error_callback = &error_cb;
1989 callbacks.post_insert_packet = delay_cb.get();
1990 callbacks.get_audio_callback = delay_cb.get();
1991
1992 test::NetEqTest test(config, codecs, ext_codecs, std::move(input),
1993 std::move(output), callbacks);
1994 test.Run();
1995 return delay_cb;
1996}
1997} // namespace
1998
1999// Plots the jitter buffer delay profile. This will plot only for the first
2000// incoming audio SSRC. If the stream contains more than one incoming audio
2001// SSRC, all but the first will be ignored.
2002void EventLogAnalyzer::CreateAudioJitterBufferGraph(
2003 const std::string& replacement_file_name,
2004 int file_sample_rate_hz,
2005 Plot* plot) {
2006 const auto& incoming_audio_kv = std::find_if(
2007 rtp_packets_.begin(), rtp_packets_.end(),
2008 [this](std::pair<StreamId, std::vector<LoggedRtpPacket>> kv) {
2009 return kv.first.GetDirection() == kIncomingPacket &&
2010 this->IsAudioSsrc(kv.first);
2011 });
2012 if (incoming_audio_kv == rtp_packets_.end()) {
2013 // No incoming audio stream found.
2014 return;
2015 }
2016
2017 const uint32_t ssrc = incoming_audio_kv->first.GetSsrc();
2018
2019 std::map<uint32_t, std::vector<uint64_t>>::const_iterator output_events_it =
2020 audio_playout_events_.find(ssrc);
2021 if (output_events_it == audio_playout_events_.end()) {
2022 // Could not find output events with SSRC matching the input audio stream.
2023 // Using the first available stream of output events.
2024 output_events_it = audio_playout_events_.cbegin();
2025 }
2026
2027 rtc::Optional<uint64_t> end_time_us =
2028 log_segments_.empty()
Oskar Sundbom3928dbc2017-11-16 10:53:09 +01002029 ? rtc::nullopt
henrik.lundin3c938fc2017-06-14 06:09:58 -07002030 : rtc::Optional<uint64_t>(log_segments_.front().second);
2031
2032 auto delay_cb = CreateNetEqTestAndRun(
2033 &incoming_audio_kv->second, &output_events_it->second, end_time_us,
2034 replacement_file_name, file_sample_rate_hz);
2035
2036 std::vector<float> send_times_s;
2037 std::vector<float> arrival_delay_ms;
2038 std::vector<float> corrected_arrival_delay_ms;
2039 std::vector<rtc::Optional<float>> playout_delay_ms;
2040 std::vector<rtc::Optional<float>> target_delay_ms;
2041 delay_cb->CreateGraphs(&send_times_s, &arrival_delay_ms,
2042 &corrected_arrival_delay_ms, &playout_delay_ms,
2043 &target_delay_ms);
2044 RTC_DCHECK_EQ(send_times_s.size(), arrival_delay_ms.size());
2045 RTC_DCHECK_EQ(send_times_s.size(), corrected_arrival_delay_ms.size());
2046 RTC_DCHECK_EQ(send_times_s.size(), playout_delay_ms.size());
2047 RTC_DCHECK_EQ(send_times_s.size(), target_delay_ms.size());
2048
2049 std::map<StreamId, TimeSeries> time_series_packet_arrival;
2050 std::map<StreamId, TimeSeries> time_series_relative_packet_arrival;
2051 std::map<StreamId, TimeSeries> time_series_play_time;
2052 std::map<StreamId, TimeSeries> time_series_target_time;
2053 float min_y_axis = 0.f;
2054 float max_y_axis = 0.f;
2055 const StreamId stream_id = incoming_audio_kv->first;
2056 for (size_t i = 0; i < send_times_s.size(); ++i) {
2057 time_series_packet_arrival[stream_id].points.emplace_back(
2058 TimeSeriesPoint(send_times_s[i], arrival_delay_ms[i]));
2059 time_series_relative_packet_arrival[stream_id].points.emplace_back(
2060 TimeSeriesPoint(send_times_s[i], corrected_arrival_delay_ms[i]));
2061 min_y_axis = std::min(min_y_axis, corrected_arrival_delay_ms[i]);
2062 max_y_axis = std::max(max_y_axis, corrected_arrival_delay_ms[i]);
2063 if (playout_delay_ms[i]) {
2064 time_series_play_time[stream_id].points.emplace_back(
2065 TimeSeriesPoint(send_times_s[i], *playout_delay_ms[i]));
2066 min_y_axis = std::min(min_y_axis, *playout_delay_ms[i]);
2067 max_y_axis = std::max(max_y_axis, *playout_delay_ms[i]);
2068 }
2069 if (target_delay_ms[i]) {
2070 time_series_target_time[stream_id].points.emplace_back(
2071 TimeSeriesPoint(send_times_s[i], *target_delay_ms[i]));
2072 min_y_axis = std::min(min_y_axis, *target_delay_ms[i]);
2073 max_y_axis = std::max(max_y_axis, *target_delay_ms[i]);
2074 }
2075 }
2076
2077 // This code is adapted for a single stream. The creation of the streams above
2078 // guarantee that no more than one steam is included. If multiple streams are
2079 // to be plotted, they should likely be given distinct labels below.
2080 RTC_DCHECK_EQ(time_series_relative_packet_arrival.size(), 1);
2081 for (auto& series : time_series_relative_packet_arrival) {
2082 series.second.label = "Relative packet arrival delay";
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01002083 series.second.line_style = LineStyle::kLine;
henrik.lundin3c938fc2017-06-14 06:09:58 -07002084 plot->AppendTimeSeries(std::move(series.second));
2085 }
2086 RTC_DCHECK_EQ(time_series_play_time.size(), 1);
2087 for (auto& series : time_series_play_time) {
2088 series.second.label = "Playout delay";
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01002089 series.second.line_style = LineStyle::kLine;
henrik.lundin3c938fc2017-06-14 06:09:58 -07002090 plot->AppendTimeSeries(std::move(series.second));
2091 }
2092 RTC_DCHECK_EQ(time_series_target_time.size(), 1);
2093 for (auto& series : time_series_target_time) {
2094 series.second.label = "Target delay";
Bjorn Tereliusb577d5e2017-11-10 16:21:34 +01002095 series.second.line_style = LineStyle::kLine;
2096 series.second.point_style = PointStyle::kHighlight;
henrik.lundin3c938fc2017-06-14 06:09:58 -07002097 plot->AppendTimeSeries(std::move(series.second));
2098 }
2099
2100 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
2101 plot->SetYAxis(min_y_axis, max_y_axis, "Relative delay (ms)", kBottomMargin,
2102 kTopMargin);
2103 plot->SetTitle("NetEq timing");
2104}
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002105
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002106void EventLogAnalyzer::CreateIceCandidatePairConfigGraph(Plot* plot) {
2107 std::map<uint32_t, TimeSeries> configs_by_cp_id;
2108 for (const auto& config : ice_candidate_pair_configs_) {
2109 if (configs_by_cp_id.find(config.candidate_pair_id) ==
2110 configs_by_cp_id.end()) {
2111 const std::string candidate_pair_desc =
2112 GetCandidatePairLogDescriptionAsString(config);
Qingsi Wang93a84392018-01-30 17:13:09 -08002113 configs_by_cp_id[config.candidate_pair_id] =
2114 TimeSeries("[" + std::to_string(config.candidate_pair_id) + "]" +
2115 candidate_pair_desc,
2116 LineStyle::kNone, PointStyle::kHighlight);
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002117 candidate_pair_desc_by_id_[config.candidate_pair_id] =
2118 candidate_pair_desc;
2119 }
2120 float x = ToCallTime(config.timestamp);
2121 float y = static_cast<float>(config.type);
2122 configs_by_cp_id[config.candidate_pair_id].points.emplace_back(x, y);
2123 }
2124
2125 // TODO(qingsi): There can be a large number of candidate pairs generated by
2126 // certain calls and the frontend cannot render the chart in this case due to
2127 // the failure of generating a palette with the same number of colors.
2128 for (auto& kv : configs_by_cp_id) {
2129 plot->AppendTimeSeries(std::move(kv.second));
2130 }
2131
2132 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
2133 plot->SetSuggestedYAxis(0, 3, "Numeric Config Type", kBottomMargin,
2134 kTopMargin);
2135 plot->SetTitle("[IceEventLog] ICE candidate pair configs");
2136}
2137
2138std::string EventLogAnalyzer::GetCandidatePairLogDescriptionFromId(
2139 uint32_t candidate_pair_id) {
2140 if (candidate_pair_desc_by_id_.find(candidate_pair_id) !=
2141 candidate_pair_desc_by_id_.end()) {
2142 return candidate_pair_desc_by_id_[candidate_pair_id];
2143 }
2144 for (const auto& config : ice_candidate_pair_configs_) {
2145 // TODO(qingsi): Add the handling of the "Updated" config event after the
2146 // visualization of property change for candidate pairs is introduced.
2147 if (candidate_pair_desc_by_id_.find(config.candidate_pair_id) ==
2148 candidate_pair_desc_by_id_.end()) {
2149 const std::string candidate_pair_desc =
2150 GetCandidatePairLogDescriptionAsString(config);
2151 candidate_pair_desc_by_id_[config.candidate_pair_id] =
2152 candidate_pair_desc;
2153 }
2154 }
2155 return candidate_pair_desc_by_id_[candidate_pair_id];
2156}
2157
2158void EventLogAnalyzer::CreateIceConnectivityCheckGraph(Plot* plot) {
2159 std::map<uint32_t, TimeSeries> checks_by_cp_id;
2160 for (const auto& event : ice_candidate_pair_events_) {
2161 if (checks_by_cp_id.find(event.candidate_pair_id) ==
2162 checks_by_cp_id.end()) {
2163 checks_by_cp_id[event.candidate_pair_id] = TimeSeries(
Qingsi Wang93a84392018-01-30 17:13:09 -08002164 "[" + std::to_string(event.candidate_pair_id) + "]" +
2165 GetCandidatePairLogDescriptionFromId(event.candidate_pair_id),
Qingsi Wang8eca1ff2018-02-02 11:49:44 -08002166 LineStyle::kNone, PointStyle::kHighlight);
2167 }
2168 float x = ToCallTime(event.timestamp);
2169 float y = static_cast<float>(event.type);
2170 checks_by_cp_id[event.candidate_pair_id].points.emplace_back(x, y);
2171 }
2172
2173 // TODO(qingsi): The same issue as in CreateIceCandidatePairConfigGraph.
2174 for (auto& kv : checks_by_cp_id) {
2175 plot->AppendTimeSeries(std::move(kv.second));
2176 }
2177
2178 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
2179 plot->SetSuggestedYAxis(0, 4, "Numeric Connectivity State", kBottomMargin,
2180 kTopMargin);
2181 plot->SetTitle("[IceEventLog] ICE connectivity checks");
2182}
2183
Bjorn Terelius2eb31882017-11-30 15:15:25 +01002184void EventLogAnalyzer::Notification(
2185 std::unique_ptr<TriageNotification> notification) {
2186 notifications_.push_back(std::move(notification));
2187}
2188
2189void EventLogAnalyzer::PrintNotifications(FILE* file) {
2190 if (notifications_.size() == 0)
2191 return;
2192 fprintf(file, "========== TRIAGE NOTIFICATIONS ==========\n");
2193 for (const auto& notification : notifications_) {
2194 rtc::Optional<float> call_timestamp = notification->Time();
2195 if (call_timestamp.has_value()) {
2196 fprintf(file, "%3.3lf s : %s\n", call_timestamp.value(),
2197 notification->ToString().c_str());
2198 } else {
2199 fprintf(file, " : %s\n", notification->ToString().c_str());
2200 }
2201 }
2202 fprintf(file, "========== END TRIAGE NOTIFICATIONS ==========\n");
2203}
2204
2205// TODO(terelius): Notifications could possibly be generated by the same code
2206// that produces the graphs. There is some code duplication that could be
2207// avoided, but that might be solved anyway when we move functionality from the
2208// analyzer to the parser.
2209void EventLogAnalyzer::CreateTriageNotifications() {
2210 uint64_t end_time_us = log_segments_.empty()
2211 ? std::numeric_limits<uint64_t>::max()
2212 : log_segments_.front().second;
2213 // Check for gaps in sequence numbers and capture timestamps.
2214 for (auto& kv : rtp_packets_) {
2215 StreamId stream_id = kv.first;
2216 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
2217
2218 SeqNumUnwrapper<uint16_t> seq_no_unwrapper;
2219 rtc::Optional<int64_t> last_seq_no;
2220 SeqNumUnwrapper<uint32_t> timestamp_unwrapper;
2221 rtc::Optional<int64_t> last_timestamp;
2222 for (const auto& packet : packet_stream) {
2223 if (packet.timestamp > end_time_us) {
2224 // Only process the first (LOG_START, LOG_END) segment.
2225 break;
2226 }
2227 int64_t seq_no = seq_no_unwrapper.Unwrap(packet.header.sequenceNumber);
2228 if (last_seq_no.has_value() &&
2229 std::abs(seq_no - last_seq_no.value()) > 1000) {
2230 // With roughly 100 packets per second (~800kbps), this would require 10
2231 // seconds without data to trigger incorrectly.
2232 if (stream_id.GetDirection() == kIncomingPacket) {
2233 Notification(rtc::MakeUnique<IncomingSeqNoJump>(
2234 ToCallTime(packet.timestamp), packet.header.ssrc));
2235 } else {
2236 Notification(rtc::MakeUnique<OutgoingSeqNoJump>(
2237 ToCallTime(packet.timestamp), packet.header.ssrc));
2238 }
2239 }
2240 last_seq_no.emplace(seq_no);
2241 int64_t timestamp = timestamp_unwrapper.Unwrap(packet.header.timestamp);
2242 if (last_timestamp.has_value() &&
2243 std::abs(timestamp - last_timestamp.value()) > 900000) {
2244 // With a 90 kHz clock, this would require 10 seconds without data to
2245 // trigger incorrectly.
2246 if (stream_id.GetDirection() == kIncomingPacket) {
2247 Notification(rtc::MakeUnique<IncomingCaptureTimeJump>(
2248 ToCallTime(packet.timestamp), packet.header.ssrc));
2249 } else {
2250 Notification(rtc::MakeUnique<OutgoingCaptureTimeJump>(
2251 ToCallTime(packet.timestamp), packet.header.ssrc));
2252 }
2253 }
2254 last_timestamp.emplace(timestamp);
2255 }
2256 }
2257
2258 // Check for gaps in RTP and RTCP streams
2259 for (const auto direction :
2260 {PacketDirection::kIncomingPacket, PacketDirection::kOutgoingPacket}) {
2261 // TODO(terelius): The parser could provide a list of all packets, ordered
2262 // by time, for each direction.
2263 std::multimap<uint64_t, const LoggedRtpPacket*> rtp_in_direction;
2264 for (const auto& kv : rtp_packets_) {
2265 if (kv.first.GetDirection() == direction) {
2266 for (const LoggedRtpPacket& rtp_packet : kv.second)
2267 rtp_in_direction.emplace(rtp_packet.timestamp, &rtp_packet);
2268 }
2269 }
2270 rtc::Optional<uint64_t> last_rtp_packet;
2271 for (const auto& kv : rtp_in_direction) {
2272 uint64_t timestamp = kv.first;
2273 if (timestamp > end_time_us) {
2274 // Only process the first (LOG_START, LOG_END) segment.
2275 break;
2276 }
2277 int64_t duration = timestamp - last_rtp_packet.value_or(0);
2278 if (last_rtp_packet.has_value() && duration > 500000) {
2279 // No incoming packet for more than 500 ms.
2280 if (direction == kIncomingPacket) {
2281 Notification(rtc::MakeUnique<IncomingRtpReceiveTimeGap>(
2282 ToCallTime(timestamp), duration / 1000));
2283 } else {
2284 Notification(rtc::MakeUnique<OutgoingRtpSendTimeGap>(
2285 ToCallTime(timestamp), duration / 1000));
2286 }
2287 }
2288 last_rtp_packet.emplace(timestamp);
2289 }
2290
2291 // TODO(terelius): The parser could provide a list of all packets, ordered
2292 // by time, for each direction.
2293 std::multimap<uint64_t, const LoggedRtcpPacket*> rtcp_in_direction;
2294 for (const auto& kv : rtcp_packets_) {
2295 if (kv.first.GetDirection() == direction) {
2296 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
2297 rtcp_in_direction.emplace(rtcp_packet.timestamp, &rtcp_packet);
2298 }
2299 }
2300 rtc::Optional<uint64_t> last_incoming_rtcp_packet;
2301 for (const auto& kv : rtcp_in_direction) {
2302 uint64_t timestamp = kv.first;
2303 if (timestamp > end_time_us) {
2304 // Only process the first (LOG_START, LOG_END) segment.
2305 break;
2306 }
2307 int64_t duration = timestamp - last_incoming_rtcp_packet.value_or(0);
2308 if (last_incoming_rtcp_packet.has_value() && duration > 2000000) {
2309 // No incoming feedback for more than 2000 ms.
2310 if (direction == kIncomingPacket) {
2311 Notification(rtc::MakeUnique<IncomingRtcpReceiveTimeGap>(
2312 ToCallTime(timestamp), duration / 1000));
2313 } else {
2314 Notification(rtc::MakeUnique<OutgoingRtcpSendTimeGap>(
2315 ToCallTime(timestamp), duration / 1000));
2316 }
2317 }
2318 last_incoming_rtcp_packet.emplace(timestamp);
2319 }
2320 }
2321
2322 // Loss feedback
2323 int64_t total_lost_packets = 0;
2324 int64_t total_expected_packets = 0;
2325 for (auto& bwe_update : bwe_loss_updates_) {
2326 if (bwe_update.timestamp > end_time_us) {
2327 // Only process the first (LOG_START, LOG_END) segment.
2328 break;
2329 }
2330 int64_t lost_packets = static_cast<double>(bwe_update.fraction_loss) / 255 *
2331 bwe_update.expected_packets;
2332 total_lost_packets += lost_packets;
2333 total_expected_packets += bwe_update.expected_packets;
2334 }
2335 double avg_outgoing_loss =
2336 static_cast<double>(total_lost_packets) / total_expected_packets;
2337 if (avg_outgoing_loss > 0.05) {
2338 Notification(rtc::MakeUnique<OutgoingHighLoss>(avg_outgoing_loss));
2339 }
2340}
2341
terelius54ce6802016-07-13 06:44:41 -07002342} // namespace plotting
2343} // namespace webrtc