blob: b42f0820f48dd878e8263dd03aaf51747769d74b [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
kjellanderd2b63cf2017-06-30 03:04:59 -070011#include "webrtc/rtc_tools/event_log_visualizer/analyzer.h"
terelius54ce6802016-07-13 06:44:41 -070012
13#include <algorithm>
14#include <limits>
15#include <map>
16#include <sstream>
17#include <string>
18#include <utility>
19
ossuf515ab82016-12-07 04:52:58 -080020#include "webrtc/call/audio_receive_stream.h"
21#include "webrtc/call/audio_send_stream.h"
22#include "webrtc/call/call.h"
terelius54ce6802016-07-13 06:44:41 -070023#include "webrtc/common_types.h"
henrik.lundin3c938fc2017-06-14 06:09:58 -070024#include "webrtc/modules/audio_coding/neteq/tools/audio_sink.h"
25#include "webrtc/modules/audio_coding/neteq/tools/fake_decode_from_file.h"
26#include "webrtc/modules/audio_coding/neteq/tools/neteq_delay_analyzer.h"
27#include "webrtc/modules/audio_coding/neteq/tools/neteq_replacement_input.h"
28#include "webrtc/modules/audio_coding/neteq/tools/neteq_test.h"
29#include "webrtc/modules/audio_coding/neteq/tools/resample_input_audio_file.h"
Stefan Holmer13181032016-07-29 14:48:54 +020030#include "webrtc/modules/congestion_controller/include/congestion_controller.h"
terelius4c9b4af2017-01-30 08:44:51 -080031#include "webrtc/modules/include/module_common_types.h"
terelius54ce6802016-07-13 06:44:41 -070032#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp.h"
33#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
danilchapbf369fe2016-10-07 07:39:54 -070034#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
stefane372d3c2017-02-02 08:04:18 -080035#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/receiver_report.h"
terelius2c8e8a32017-06-02 01:29:48 -070036#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.h"
stefane372d3c2017-02-02 08:04:18 -080037#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sender_report.h"
Stefan Holmer13181032016-07-29 14:48:54 +020038#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
ossuf515ab82016-12-07 04:52:58 -080039#include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h"
40#include "webrtc/modules/rtp_rtcp/source/rtp_utility.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020041#include "webrtc/rtc_base/checks.h"
42#include "webrtc/rtc_base/format_macros.h"
43#include "webrtc/rtc_base/logging.h"
44#include "webrtc/rtc_base/ptr_util.h"
45#include "webrtc/rtc_base/rate_statistics.h"
terelius54ce6802016-07-13 06:44:41 -070046#include "webrtc/video_receive_stream.h"
47#include "webrtc/video_send_stream.h"
48
tereliusdc35dcd2016-08-01 12:03:27 -070049namespace webrtc {
50namespace plotting {
51
terelius54ce6802016-07-13 06:44:41 -070052namespace {
53
elad.alonec304f92017-03-08 05:03:53 -080054void SortPacketFeedbackVector(std::vector<PacketFeedback>* vec) {
55 auto pred = [](const PacketFeedback& packet_feedback) {
56 return packet_feedback.arrival_time_ms == PacketFeedback::kNotReceived;
57 };
58 vec->erase(std::remove_if(vec->begin(), vec->end(), pred), vec->end());
59 std::sort(vec->begin(), vec->end(), PacketFeedbackComparator());
60}
61
terelius54ce6802016-07-13 06:44:41 -070062std::string SsrcToString(uint32_t ssrc) {
63 std::stringstream ss;
64 ss << "SSRC " << ssrc;
65 return ss.str();
66}
67
68// Checks whether an SSRC is contained in the list of desired SSRCs.
69// Note that an empty SSRC list matches every SSRC.
70bool MatchingSsrc(uint32_t ssrc, const std::vector<uint32_t>& desired_ssrc) {
71 if (desired_ssrc.size() == 0)
72 return true;
73 return std::find(desired_ssrc.begin(), desired_ssrc.end(), ssrc) !=
74 desired_ssrc.end();
75}
76
77double AbsSendTimeToMicroseconds(int64_t abs_send_time) {
78 // The timestamp is a fixed point representation with 6 bits for seconds
79 // and 18 bits for fractions of a second. Thus, we divide by 2^18 to get the
80 // time in seconds and then multiply by 1000000 to convert to microseconds.
81 static constexpr double kTimestampToMicroSec =
tereliusccbbf8d2016-08-10 07:34:28 -070082 1000000.0 / static_cast<double>(1ul << 18);
terelius54ce6802016-07-13 06:44:41 -070083 return abs_send_time * kTimestampToMicroSec;
84}
85
86// Computes the difference |later| - |earlier| where |later| and |earlier|
87// are counters that wrap at |modulus|. The difference is chosen to have the
88// least absolute value. For example if |modulus| is 8, then the difference will
89// be chosen in the range [-3, 4]. If |modulus| is 9, then the difference will
90// be in [-4, 4].
91int64_t WrappingDifference(uint32_t later, uint32_t earlier, int64_t modulus) {
92 RTC_DCHECK_LE(1, modulus);
93 RTC_DCHECK_LT(later, modulus);
94 RTC_DCHECK_LT(earlier, modulus);
95 int64_t difference =
96 static_cast<int64_t>(later) - static_cast<int64_t>(earlier);
97 int64_t max_difference = modulus / 2;
98 int64_t min_difference = max_difference - modulus + 1;
99 if (difference > max_difference) {
100 difference -= modulus;
101 }
102 if (difference < min_difference) {
103 difference += modulus;
104 }
terelius6addf492016-08-23 17:34:07 -0700105 if (difference > max_difference / 2 || difference < min_difference / 2) {
106 LOG(LS_WARNING) << "Difference between" << later << " and " << earlier
107 << " expected to be in the range (" << min_difference / 2
108 << "," << max_difference / 2 << ") but is " << difference
109 << ". Correct unwrapping is uncertain.";
110 }
terelius54ce6802016-07-13 06:44:41 -0700111 return difference;
112}
113
ivocaac9d6f2016-09-22 07:01:47 -0700114// Return default values for header extensions, to use on streams without stored
115// mapping data. Currently this only applies to audio streams, since the mapping
116// is not stored in the event log.
117// TODO(ivoc): Remove this once this mapping is stored in the event log for
118// audio streams. Tracking bug: webrtc:6399
119webrtc::RtpHeaderExtensionMap GetDefaultHeaderExtensionMap() {
120 webrtc::RtpHeaderExtensionMap default_map;
danilchap4aecc582016-11-15 09:21:00 -0800121 default_map.Register<AudioLevel>(webrtc::RtpExtension::kAudioLevelDefaultId);
122 default_map.Register<AbsoluteSendTime>(
ivocaac9d6f2016-09-22 07:01:47 -0700123 webrtc::RtpExtension::kAbsSendTimeDefaultId);
124 return default_map;
125}
126
tereliusdc35dcd2016-08-01 12:03:27 -0700127constexpr float kLeftMargin = 0.01f;
128constexpr float kRightMargin = 0.02f;
129constexpr float kBottomMargin = 0.02f;
130constexpr float kTopMargin = 0.05f;
terelius54ce6802016-07-13 06:44:41 -0700131
terelius53dc23c2017-03-13 05:24:05 -0700132rtc::Optional<double> NetworkDelayDiff_AbsSendTime(
133 const LoggedRtpPacket& old_packet,
134 const LoggedRtpPacket& new_packet) {
135 if (old_packet.header.extension.hasAbsoluteSendTime &&
136 new_packet.header.extension.hasAbsoluteSendTime) {
137 int64_t send_time_diff = WrappingDifference(
138 new_packet.header.extension.absoluteSendTime,
139 old_packet.header.extension.absoluteSendTime, 1ul << 24);
140 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
141 double delay_change_us =
142 recv_time_diff - AbsSendTimeToMicroseconds(send_time_diff);
143 return rtc::Optional<double>(delay_change_us / 1000);
144 } else {
145 return rtc::Optional<double>();
terelius6addf492016-08-23 17:34:07 -0700146 }
147}
148
terelius53dc23c2017-03-13 05:24:05 -0700149rtc::Optional<double> NetworkDelayDiff_CaptureTime(
150 const LoggedRtpPacket& old_packet,
151 const LoggedRtpPacket& new_packet) {
152 int64_t send_time_diff = WrappingDifference(
153 new_packet.header.timestamp, old_packet.header.timestamp, 1ull << 32);
154 int64_t recv_time_diff = new_packet.timestamp - old_packet.timestamp;
155
156 const double kVideoSampleRate = 90000;
157 // TODO(terelius): We treat all streams as video for now, even though
158 // audio might be sampled at e.g. 16kHz, because it is really difficult to
159 // figure out the true sampling rate of a stream. The effect is that the
160 // delay will be scaled incorrectly for non-video streams.
161
162 double delay_change =
163 static_cast<double>(recv_time_diff) / 1000 -
164 static_cast<double>(send_time_diff) / kVideoSampleRate * 1000;
165 if (delay_change < -10000 || 10000 < delay_change) {
166 LOG(LS_WARNING) << "Very large delay change. Timestamps correct?";
167 LOG(LS_WARNING) << "Old capture time " << old_packet.header.timestamp
168 << ", received time " << old_packet.timestamp;
169 LOG(LS_WARNING) << "New capture time " << new_packet.header.timestamp
170 << ", received time " << new_packet.timestamp;
171 LOG(LS_WARNING) << "Receive time difference " << recv_time_diff << " = "
172 << static_cast<double>(recv_time_diff) / 1000000 << "s";
173 LOG(LS_WARNING) << "Send time difference " << send_time_diff << " = "
174 << static_cast<double>(send_time_diff) / kVideoSampleRate
175 << "s";
176 }
177 return rtc::Optional<double>(delay_change);
178}
179
180// For each element in data, use |get_y()| to extract a y-coordinate and
181// store the result in a TimeSeries.
182template <typename DataType>
183void ProcessPoints(
184 rtc::FunctionView<rtc::Optional<float>(const DataType&)> get_y,
185 const std::vector<DataType>& data,
186 uint64_t begin_time,
187 TimeSeries* result) {
188 for (size_t i = 0; i < data.size(); i++) {
189 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
190 rtc::Optional<float> y = get_y(data[i]);
191 if (y)
192 result->points.emplace_back(x, *y);
193 }
194}
195
196// For each pair of adjacent elements in |data|, use |get_y| to extract a
terelius6addf492016-08-23 17:34:07 -0700197// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
198// will be the time of the second element in the pair.
terelius53dc23c2017-03-13 05:24:05 -0700199template <typename DataType, typename ResultType>
200void ProcessPairs(
201 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&,
202 const DataType&)> get_y,
203 const std::vector<DataType>& data,
204 uint64_t begin_time,
205 TimeSeries* result) {
tereliusccbbf8d2016-08-10 07:34:28 -0700206 for (size_t i = 1; i < data.size(); i++) {
207 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
terelius53dc23c2017-03-13 05:24:05 -0700208 rtc::Optional<ResultType> y = get_y(data[i - 1], data[i]);
209 if (y)
210 result->points.emplace_back(x, static_cast<float>(*y));
211 }
212}
213
214// For each element in data, use |extract()| to extract a y-coordinate and
215// store the result in a TimeSeries.
216template <typename DataType, typename ResultType>
217void AccumulatePoints(
218 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract,
219 const std::vector<DataType>& data,
220 uint64_t begin_time,
221 TimeSeries* result) {
222 ResultType sum = 0;
223 for (size_t i = 0; i < data.size(); i++) {
224 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
225 rtc::Optional<ResultType> y = extract(data[i]);
226 if (y) {
227 sum += *y;
228 result->points.emplace_back(x, static_cast<float>(sum));
229 }
230 }
231}
232
233// For each pair of adjacent elements in |data|, use |extract()| to extract a
234// y-coordinate and store the result in a TimeSeries. Note that the x-coordinate
235// will be the time of the second element in the pair.
236template <typename DataType, typename ResultType>
237void AccumulatePairs(
238 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&,
239 const DataType&)> extract,
240 const std::vector<DataType>& data,
241 uint64_t begin_time,
242 TimeSeries* result) {
243 ResultType sum = 0;
244 for (size_t i = 1; i < data.size(); i++) {
245 float x = static_cast<float>(data[i].timestamp - begin_time) / 1000000;
246 rtc::Optional<ResultType> y = extract(data[i - 1], data[i]);
247 if (y)
248 sum += *y;
249 result->points.emplace_back(x, static_cast<float>(sum));
tereliusccbbf8d2016-08-10 07:34:28 -0700250 }
251}
252
terelius6addf492016-08-23 17:34:07 -0700253// Calculates a moving average of |data| and stores the result in a TimeSeries.
254// A data point is generated every |step| microseconds from |begin_time|
255// to |end_time|. The value of each data point is the average of the data
256// during the preceeding |window_duration_us| microseconds.
terelius53dc23c2017-03-13 05:24:05 -0700257template <typename DataType, typename ResultType>
258void MovingAverage(
259 rtc::FunctionView<rtc::Optional<ResultType>(const DataType&)> extract,
260 const std::vector<DataType>& data,
261 uint64_t begin_time,
262 uint64_t end_time,
263 uint64_t window_duration_us,
264 uint64_t step,
265 webrtc::plotting::TimeSeries* result) {
terelius6addf492016-08-23 17:34:07 -0700266 size_t window_index_begin = 0;
267 size_t window_index_end = 0;
terelius53dc23c2017-03-13 05:24:05 -0700268 ResultType sum_in_window = 0;
terelius6addf492016-08-23 17:34:07 -0700269
270 for (uint64_t t = begin_time; t < end_time + step; t += step) {
271 while (window_index_end < data.size() &&
272 data[window_index_end].timestamp < t) {
terelius53dc23c2017-03-13 05:24:05 -0700273 rtc::Optional<ResultType> value = extract(data[window_index_end]);
274 if (value)
275 sum_in_window += *value;
terelius6addf492016-08-23 17:34:07 -0700276 ++window_index_end;
277 }
278 while (window_index_begin < data.size() &&
279 data[window_index_begin].timestamp < t - window_duration_us) {
terelius53dc23c2017-03-13 05:24:05 -0700280 rtc::Optional<ResultType> value = extract(data[window_index_begin]);
281 if (value)
282 sum_in_window -= *value;
terelius6addf492016-08-23 17:34:07 -0700283 ++window_index_begin;
284 }
285 float window_duration_s = static_cast<float>(window_duration_us) / 1000000;
286 float x = static_cast<float>(t - begin_time) / 1000000;
terelius53dc23c2017-03-13 05:24:05 -0700287 float y = sum_in_window / window_duration_s;
terelius6addf492016-08-23 17:34:07 -0700288 result->points.emplace_back(x, y);
289 }
290}
291
terelius54ce6802016-07-13 06:44:41 -0700292} // namespace
293
terelius54ce6802016-07-13 06:44:41 -0700294EventLogAnalyzer::EventLogAnalyzer(const ParsedRtcEventLog& log)
295 : parsed_log_(log), window_duration_(250000), step_(10000) {
296 uint64_t first_timestamp = std::numeric_limits<uint64_t>::max();
297 uint64_t last_timestamp = std::numeric_limits<uint64_t>::min();
terelius88e64e52016-07-19 01:51:06 -0700298
terelius88e64e52016-07-19 01:51:06 -0700299 PacketDirection direction;
terelius88e64e52016-07-19 01:51:06 -0700300 uint8_t header[IP_PACKET_SIZE];
301 size_t header_length;
302 size_t total_length;
303
perkjbbbad6d2017-05-19 06:30:28 -0700304 uint8_t last_incoming_rtcp_packet[IP_PACKET_SIZE];
305 uint8_t last_incoming_rtcp_packet_length = 0;
306
ivocaac9d6f2016-09-22 07:01:47 -0700307 // Make a default extension map for streams without configuration information.
308 // TODO(ivoc): Once configuration of audio streams is stored in the event log,
309 // this can be removed. Tracking bug: webrtc:6399
310 RtpHeaderExtensionMap default_extension_map = GetDefaultHeaderExtensionMap();
311
henrik.lundin3c938fc2017-06-14 06:09:58 -0700312 rtc::Optional<uint64_t> last_log_start;
313
terelius54ce6802016-07-13 06:44:41 -0700314 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
315 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
terelius88e64e52016-07-19 01:51:06 -0700316 if (event_type != ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT &&
317 event_type != ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT &&
318 event_type != ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT &&
terelius88c1d2b2016-08-01 05:20:33 -0700319 event_type != ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT &&
320 event_type != ParsedRtcEventLog::LOG_START &&
321 event_type != ParsedRtcEventLog::LOG_END) {
terelius88e64e52016-07-19 01:51:06 -0700322 uint64_t timestamp = parsed_log_.GetTimestamp(i);
323 first_timestamp = std::min(first_timestamp, timestamp);
324 last_timestamp = std::max(last_timestamp, timestamp);
325 }
326
327 switch (parsed_log_.GetEventType(i)) {
328 case ParsedRtcEventLog::VIDEO_RECEIVER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700329 rtclog::StreamConfig config = parsed_log_.GetVideoReceiveConfig(i);
perkj09e71da2017-05-22 03:26:49 -0700330 StreamId stream(config.remote_ssrc, kIncomingPacket);
terelius0740a202016-08-08 10:21:04 -0700331 video_ssrcs_.insert(stream);
perkj09e71da2017-05-22 03:26:49 -0700332 StreamId rtx_stream(config.rtx_ssrc, kIncomingPacket);
brandtr14742122017-01-27 04:53:07 -0800333 video_ssrcs_.insert(rtx_stream);
334 rtx_ssrcs_.insert(rtx_stream);
terelius88e64e52016-07-19 01:51:06 -0700335 break;
336 }
337 case ParsedRtcEventLog::VIDEO_SENDER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700338 std::vector<rtclog::StreamConfig> configs =
339 parsed_log_.GetVideoSendConfig(i);
terelius405f90c2017-06-01 03:50:31 -0700340 for (const auto& config : configs) {
341 StreamId stream(config.local_ssrc, kOutgoingPacket);
terelius8fbc7652017-05-31 02:03:16 -0700342 video_ssrcs_.insert(stream);
terelius405f90c2017-06-01 03:50:31 -0700343 StreamId rtx_stream(config.rtx_ssrc, kOutgoingPacket);
terelius8fbc7652017-05-31 02:03:16 -0700344 video_ssrcs_.insert(rtx_stream);
345 rtx_ssrcs_.insert(rtx_stream);
346 }
terelius88e64e52016-07-19 01:51:06 -0700347 break;
348 }
349 case ParsedRtcEventLog::AUDIO_RECEIVER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700350 rtclog::StreamConfig config = parsed_log_.GetAudioReceiveConfig(i);
perkjac8f52d2017-05-22 09:36:28 -0700351 StreamId stream(config.remote_ssrc, kIncomingPacket);
ivoce0928d82016-10-10 05:12:51 -0700352 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700353 break;
354 }
355 case ParsedRtcEventLog::AUDIO_SENDER_CONFIG_EVENT: {
terelius8fbc7652017-05-31 02:03:16 -0700356 rtclog::StreamConfig config = parsed_log_.GetAudioSendConfig(i);
perkjf4726992017-05-22 10:12:26 -0700357 StreamId stream(config.local_ssrc, kOutgoingPacket);
ivoce0928d82016-10-10 05:12:51 -0700358 audio_ssrcs_.insert(stream);
terelius88e64e52016-07-19 01:51:06 -0700359 break;
360 }
361 case ParsedRtcEventLog::RTP_EVENT: {
ilnika8e781a2017-06-12 01:02:46 -0700362 RtpHeaderExtensionMap* extension_map = parsed_log_.GetRtpHeader(
363 i, &direction, header, &header_length, &total_length);
terelius88e64e52016-07-19 01:51:06 -0700364 RtpUtility::RtpHeaderParser rtp_parser(header, header_length);
365 RTPHeader parsed_header;
ilnika8e781a2017-06-12 01:02:46 -0700366 if (extension_map != nullptr) {
terelius88e64e52016-07-19 01:51:06 -0700367 rtp_parser.Parse(&parsed_header, extension_map);
ivocaac9d6f2016-09-22 07:01:47 -0700368 } else {
369 // Use the default extension map.
370 // TODO(ivoc): Once configuration of audio streams is stored in the
371 // event log, this can be removed.
372 // Tracking bug: webrtc:6399
373 rtp_parser.Parse(&parsed_header, &default_extension_map);
terelius88e64e52016-07-19 01:51:06 -0700374 }
375 uint64_t timestamp = parsed_log_.GetTimestamp(i);
ilnika8e781a2017-06-12 01:02:46 -0700376 StreamId stream(parsed_header.ssrc, direction);
terelius88e64e52016-07-19 01:51:06 -0700377 rtp_packets_[stream].push_back(
Stefan Holmer13181032016-07-29 14:48:54 +0200378 LoggedRtpPacket(timestamp, parsed_header, total_length));
terelius88e64e52016-07-19 01:51:06 -0700379 break;
380 }
381 case ParsedRtcEventLog::RTCP_EVENT: {
Stefan Holmer13181032016-07-29 14:48:54 +0200382 uint8_t packet[IP_PACKET_SIZE];
perkj77cd58e2017-05-30 03:52:10 -0700383 parsed_log_.GetRtcpPacket(i, &direction, packet, &total_length);
perkjbbbad6d2017-05-19 06:30:28 -0700384 // Currently incoming RTCP packets are logged twice, both for audio and
385 // video. Only act on one of them. Compare against the previous parsed
386 // incoming RTCP packet.
387 if (direction == webrtc::kIncomingPacket) {
388 RTC_CHECK_LE(total_length, IP_PACKET_SIZE);
389 if (total_length == last_incoming_rtcp_packet_length &&
390 memcmp(last_incoming_rtcp_packet, packet, total_length) == 0) {
391 continue;
392 } else {
393 memcpy(last_incoming_rtcp_packet, packet, total_length);
394 last_incoming_rtcp_packet_length = total_length;
395 }
396 }
397 rtcp::CommonHeader header;
398 const uint8_t* packet_end = packet + total_length;
399 for (const uint8_t* block = packet; block < packet_end;
400 block = header.NextPacket()) {
401 RTC_CHECK(header.Parse(block, packet_end - block));
402 if (header.type() == rtcp::TransportFeedback::kPacketType &&
403 header.fmt() == rtcp::TransportFeedback::kFeedbackMessageType) {
404 std::unique_ptr<rtcp::TransportFeedback> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700405 rtc::MakeUnique<rtcp::TransportFeedback>());
perkjbbbad6d2017-05-19 06:30:28 -0700406 if (rtcp_packet->Parse(header)) {
407 uint32_t ssrc = rtcp_packet->sender_ssrc();
408 StreamId stream(ssrc, direction);
409 uint64_t timestamp = parsed_log_.GetTimestamp(i);
410 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
411 timestamp, kRtcpTransportFeedback, std::move(rtcp_packet)));
412 }
413 } else if (header.type() == rtcp::SenderReport::kPacketType) {
414 std::unique_ptr<rtcp::SenderReport> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700415 rtc::MakeUnique<rtcp::SenderReport>());
perkjbbbad6d2017-05-19 06:30:28 -0700416 if (rtcp_packet->Parse(header)) {
417 uint32_t ssrc = rtcp_packet->sender_ssrc();
418 StreamId stream(ssrc, direction);
419 uint64_t timestamp = parsed_log_.GetTimestamp(i);
420 rtcp_packets_[stream].push_back(
421 LoggedRtcpPacket(timestamp, kRtcpSr, std::move(rtcp_packet)));
422 }
423 } else if (header.type() == rtcp::ReceiverReport::kPacketType) {
424 std::unique_ptr<rtcp::ReceiverReport> rtcp_packet(
terelius2c8e8a32017-06-02 01:29:48 -0700425 rtc::MakeUnique<rtcp::ReceiverReport>());
perkjbbbad6d2017-05-19 06:30:28 -0700426 if (rtcp_packet->Parse(header)) {
427 uint32_t ssrc = rtcp_packet->sender_ssrc();
428 StreamId stream(ssrc, direction);
429 uint64_t timestamp = parsed_log_.GetTimestamp(i);
430 rtcp_packets_[stream].push_back(
431 LoggedRtcpPacket(timestamp, kRtcpRr, std::move(rtcp_packet)));
Stefan Holmer13181032016-07-29 14:48:54 +0200432 }
terelius2c8e8a32017-06-02 01:29:48 -0700433 } else if (header.type() == rtcp::Remb::kPacketType &&
434 header.fmt() == rtcp::Remb::kFeedbackMessageType) {
435 std::unique_ptr<rtcp::Remb> rtcp_packet(
436 rtc::MakeUnique<rtcp::Remb>());
437 if (rtcp_packet->Parse(header)) {
438 uint32_t ssrc = rtcp_packet->sender_ssrc();
439 StreamId stream(ssrc, direction);
440 uint64_t timestamp = parsed_log_.GetTimestamp(i);
441 rtcp_packets_[stream].push_back(LoggedRtcpPacket(
442 timestamp, kRtcpRemb, std::move(rtcp_packet)));
443 }
Stefan Holmer13181032016-07-29 14:48:54 +0200444 }
Stefan Holmer13181032016-07-29 14:48:54 +0200445 }
terelius88e64e52016-07-19 01:51:06 -0700446 break;
447 }
448 case ParsedRtcEventLog::LOG_START: {
henrik.lundin3c938fc2017-06-14 06:09:58 -0700449 if (last_log_start) {
450 // A LOG_END event was missing. Use last_timestamp.
451 RTC_DCHECK_GE(last_timestamp, *last_log_start);
452 log_segments_.push_back(
453 std::make_pair(*last_log_start, last_timestamp));
454 }
455 last_log_start = rtc::Optional<uint64_t>(parsed_log_.GetTimestamp(i));
terelius88e64e52016-07-19 01:51:06 -0700456 break;
457 }
458 case ParsedRtcEventLog::LOG_END: {
henrik.lundin3c938fc2017-06-14 06:09:58 -0700459 RTC_DCHECK(last_log_start);
460 log_segments_.push_back(
461 std::make_pair(*last_log_start, parsed_log_.GetTimestamp(i)));
462 last_log_start.reset();
terelius88e64e52016-07-19 01:51:06 -0700463 break;
464 }
terelius424e6cf2017-02-20 05:14:41 -0800465 case ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT: {
henrik.lundin3c938fc2017-06-14 06:09:58 -0700466 uint32_t this_ssrc;
467 parsed_log_.GetAudioPlayout(i, &this_ssrc);
468 audio_playout_events_[this_ssrc].push_back(parsed_log_.GetTimestamp(i));
terelius424e6cf2017-02-20 05:14:41 -0800469 break;
470 }
471 case ParsedRtcEventLog::LOSS_BASED_BWE_UPDATE: {
472 LossBasedBweUpdate bwe_update;
terelius8058e582016-07-25 01:32:41 -0700473 bwe_update.timestamp = parsed_log_.GetTimestamp(i);
terelius424e6cf2017-02-20 05:14:41 -0800474 parsed_log_.GetLossBasedBweUpdate(i, &bwe_update.new_bitrate,
475 &bwe_update.fraction_loss,
476 &bwe_update.expected_packets);
terelius8058e582016-07-25 01:32:41 -0700477 bwe_loss_updates_.push_back(bwe_update);
terelius88e64e52016-07-19 01:51:06 -0700478 break;
479 }
terelius424e6cf2017-02-20 05:14:41 -0800480 case ParsedRtcEventLog::DELAY_BASED_BWE_UPDATE: {
philipel10fc0e62017-04-11 01:50:23 -0700481 bwe_delay_updates_.push_back(parsed_log_.GetDelayBasedBweUpdate(i));
terelius424e6cf2017-02-20 05:14:41 -0800482 break;
483 }
minyue4b7c9522017-01-24 04:54:59 -0800484 case ParsedRtcEventLog::AUDIO_NETWORK_ADAPTATION_EVENT: {
michaelt6e5b2192017-02-22 07:33:27 -0800485 AudioNetworkAdaptationEvent ana_event;
486 ana_event.timestamp = parsed_log_.GetTimestamp(i);
487 parsed_log_.GetAudioNetworkAdaptation(i, &ana_event.config);
488 audio_network_adaptation_events_.push_back(ana_event);
minyue4b7c9522017-01-24 04:54:59 -0800489 break;
490 }
philipel32d00102017-02-27 02:18:46 -0800491 case ParsedRtcEventLog::BWE_PROBE_CLUSTER_CREATED_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200492 bwe_probe_cluster_created_events_.push_back(
493 parsed_log_.GetBweProbeClusterCreated(i));
philipel32d00102017-02-27 02:18:46 -0800494 break;
495 }
496 case ParsedRtcEventLog::BWE_PROBE_RESULT_EVENT: {
philipele127e7a2017-03-29 16:28:53 +0200497 bwe_probe_result_events_.push_back(parsed_log_.GetBweProbeResult(i));
philipel32d00102017-02-27 02:18:46 -0800498 break;
499 }
terelius88e64e52016-07-19 01:51:06 -0700500 case ParsedRtcEventLog::UNKNOWN_EVENT: {
501 break;
502 }
503 }
terelius54ce6802016-07-13 06:44:41 -0700504 }
terelius88e64e52016-07-19 01:51:06 -0700505
terelius54ce6802016-07-13 06:44:41 -0700506 if (last_timestamp < first_timestamp) {
507 // No useful events in the log.
508 first_timestamp = last_timestamp = 0;
509 }
510 begin_time_ = first_timestamp;
511 end_time_ = last_timestamp;
tereliusdc35dcd2016-08-01 12:03:27 -0700512 call_duration_s_ = static_cast<float>(end_time_ - begin_time_) / 1000000;
henrik.lundin3c938fc2017-06-14 06:09:58 -0700513 if (last_log_start) {
514 // The log was missing the last LOG_END event. Fake it.
515 log_segments_.push_back(std::make_pair(*last_log_start, end_time_));
516 }
terelius54ce6802016-07-13 06:44:41 -0700517}
518
Stefan Holmer13181032016-07-29 14:48:54 +0200519class BitrateObserver : public CongestionController::Observer,
520 public RemoteBitrateObserver {
521 public:
522 BitrateObserver() : last_bitrate_bps_(0), bitrate_updated_(false) {}
523
minyue78b4d562016-11-30 04:47:39 -0800524 // TODO(minyue): remove this when old OnNetworkChanged is deprecated. See
525 // https://bugs.chromium.org/p/webrtc/issues/detail?id=6796
526 using CongestionController::Observer::OnNetworkChanged;
527
Stefan Holmer13181032016-07-29 14:48:54 +0200528 void OnNetworkChanged(uint32_t bitrate_bps,
529 uint8_t fraction_loss,
minyue78b4d562016-11-30 04:47:39 -0800530 int64_t rtt_ms,
531 int64_t probing_interval_ms) override {
Stefan Holmer13181032016-07-29 14:48:54 +0200532 last_bitrate_bps_ = bitrate_bps;
533 bitrate_updated_ = true;
534 }
535
536 void OnReceiveBitrateChanged(const std::vector<uint32_t>& ssrcs,
537 uint32_t bitrate) override {}
538
539 uint32_t last_bitrate_bps() const { return last_bitrate_bps_; }
540 bool GetAndResetBitrateUpdated() {
541 bool bitrate_updated = bitrate_updated_;
542 bitrate_updated_ = false;
543 return bitrate_updated;
544 }
545
546 private:
547 uint32_t last_bitrate_bps_;
548 bool bitrate_updated_;
549};
550
Stefan Holmer99f8e082016-09-09 13:37:50 +0200551bool EventLogAnalyzer::IsRtxSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700552 return rtx_ssrcs_.count(stream_id) == 1;
553}
554
Stefan Holmer99f8e082016-09-09 13:37:50 +0200555bool EventLogAnalyzer::IsVideoSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700556 return video_ssrcs_.count(stream_id) == 1;
557}
558
Stefan Holmer99f8e082016-09-09 13:37:50 +0200559bool EventLogAnalyzer::IsAudioSsrc(StreamId stream_id) const {
terelius0740a202016-08-08 10:21:04 -0700560 return audio_ssrcs_.count(stream_id) == 1;
561}
562
Stefan Holmer99f8e082016-09-09 13:37:50 +0200563std::string EventLogAnalyzer::GetStreamName(StreamId stream_id) const {
564 std::stringstream name;
565 if (IsAudioSsrc(stream_id)) {
566 name << "Audio ";
567 } else if (IsVideoSsrc(stream_id)) {
568 name << "Video ";
569 } else {
570 name << "Unknown ";
571 }
572 if (IsRtxSsrc(stream_id))
573 name << "RTX ";
ivocaac9d6f2016-09-22 07:01:47 -0700574 if (stream_id.GetDirection() == kIncomingPacket) {
575 name << "(In) ";
576 } else {
577 name << "(Out) ";
578 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200579 name << SsrcToString(stream_id.GetSsrc());
580 return name.str();
581}
582
terelius54ce6802016-07-13 06:44:41 -0700583void EventLogAnalyzer::CreatePacketGraph(PacketDirection desired_direction,
584 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700585 for (auto& kv : rtp_packets_) {
586 StreamId stream_id = kv.first;
587 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
588 // Filter on direction and SSRC.
589 if (stream_id.GetDirection() != desired_direction ||
590 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
591 continue;
terelius54ce6802016-07-13 06:44:41 -0700592 }
terelius54ce6802016-07-13 06:44:41 -0700593
terelius23c595a2017-03-15 01:59:12 -0700594 TimeSeries time_series(GetStreamName(stream_id), BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700595 ProcessPoints<LoggedRtpPacket>(
596 [](const LoggedRtpPacket& packet) -> rtc::Optional<float> {
597 return rtc::Optional<float>(packet.total_length);
598 },
599 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700600 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700601 }
602
tereliusdc35dcd2016-08-01 12:03:27 -0700603 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
604 plot->SetSuggestedYAxis(0, 1, "Packet size (bytes)", kBottomMargin,
605 kTopMargin);
terelius54ce6802016-07-13 06:44:41 -0700606 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700607 plot->SetTitle("Incoming RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700608 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -0700609 plot->SetTitle("Outgoing RTP packets");
terelius54ce6802016-07-13 06:44:41 -0700610 }
611}
612
philipelccd74892016-09-05 02:46:25 -0700613template <typename T>
614void EventLogAnalyzer::CreateAccumulatedPacketsTimeSeries(
615 PacketDirection desired_direction,
616 Plot* plot,
617 const std::map<StreamId, std::vector<T>>& packets,
618 const std::string& label_prefix) {
619 for (auto& kv : packets) {
620 StreamId stream_id = kv.first;
621 const std::vector<T>& packet_stream = kv.second;
622 // Filter on direction and SSRC.
623 if (stream_id.GetDirection() != desired_direction ||
624 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
625 continue;
626 }
627
terelius23c595a2017-03-15 01:59:12 -0700628 std::string label = label_prefix + " " + GetStreamName(stream_id);
629 TimeSeries time_series(label, LINE_STEP_GRAPH);
philipelccd74892016-09-05 02:46:25 -0700630 for (size_t i = 0; i < packet_stream.size(); i++) {
631 float x = static_cast<float>(packet_stream[i].timestamp - begin_time_) /
632 1000000;
philipelccd74892016-09-05 02:46:25 -0700633 time_series.points.emplace_back(x, i + 1);
634 }
635
philipel35ba9bd2017-04-19 05:58:51 -0700636 plot->AppendTimeSeries(std::move(time_series));
philipelccd74892016-09-05 02:46:25 -0700637 }
638}
639
640void EventLogAnalyzer::CreateAccumulatedPacketsGraph(
641 PacketDirection desired_direction,
642 Plot* plot) {
643 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtp_packets_,
644 "RTP");
645 CreateAccumulatedPacketsTimeSeries(desired_direction, plot, rtcp_packets_,
646 "RTCP");
647
648 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
649 plot->SetSuggestedYAxis(0, 1, "Received Packets", kBottomMargin, kTopMargin);
650 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
651 plot->SetTitle("Accumulated Incoming RTP/RTCP packets");
652 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
653 plot->SetTitle("Accumulated Outgoing RTP/RTCP packets");
654 }
655}
656
terelius54ce6802016-07-13 06:44:41 -0700657// For each SSRC, plot the time between the consecutive playouts.
658void EventLogAnalyzer::CreatePlayoutGraph(Plot* plot) {
659 std::map<uint32_t, TimeSeries> time_series;
660 std::map<uint32_t, uint64_t> last_playout;
661
662 uint32_t ssrc;
terelius54ce6802016-07-13 06:44:41 -0700663
664 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
665 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
666 if (event_type == ParsedRtcEventLog::AUDIO_PLAYOUT_EVENT) {
667 parsed_log_.GetAudioPlayout(i, &ssrc);
668 uint64_t timestamp = parsed_log_.GetTimestamp(i);
669 if (MatchingSsrc(ssrc, desired_ssrc_)) {
670 float x = static_cast<float>(timestamp - begin_time_) / 1000000;
671 float y = static_cast<float>(timestamp - last_playout[ssrc]) / 1000;
672 if (time_series[ssrc].points.size() == 0) {
673 // There were no previusly logged playout for this SSRC.
674 // Generate a point, but place it on the x-axis.
675 y = 0;
676 }
terelius54ce6802016-07-13 06:44:41 -0700677 time_series[ssrc].points.push_back(TimeSeriesPoint(x, y));
678 last_playout[ssrc] = timestamp;
679 }
680 }
681 }
682
683 // Set labels and put in graph.
684 for (auto& kv : time_series) {
685 kv.second.label = SsrcToString(kv.first);
686 kv.second.style = BAR_GRAPH;
philipel35ba9bd2017-04-19 05:58:51 -0700687 plot->AppendTimeSeries(std::move(kv.second));
terelius54ce6802016-07-13 06:44:41 -0700688 }
689
tereliusdc35dcd2016-08-01 12:03:27 -0700690 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
691 plot->SetSuggestedYAxis(0, 1, "Time since last playout (ms)", kBottomMargin,
692 kTopMargin);
693 plot->SetTitle("Audio playout");
terelius54ce6802016-07-13 06:44:41 -0700694}
695
ivocaac9d6f2016-09-22 07:01:47 -0700696// For audio SSRCs, plot the audio level.
697void EventLogAnalyzer::CreateAudioLevelGraph(Plot* plot) {
698 std::map<StreamId, TimeSeries> time_series;
699
700 for (auto& kv : rtp_packets_) {
701 StreamId stream_id = kv.first;
702 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
703 // TODO(ivoc): When audio send/receive configs are stored in the event
704 // log, a check should be added here to only process audio
705 // streams. Tracking bug: webrtc:6399
706 for (auto& packet : packet_stream) {
707 if (packet.header.extension.hasAudioLevel) {
708 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
709 // The audio level is stored in -dBov (so e.g. -10 dBov is stored as 10)
710 // Here we convert it to dBov.
711 float y = static_cast<float>(-packet.header.extension.audioLevel);
712 time_series[stream_id].points.emplace_back(TimeSeriesPoint(x, y));
713 }
714 }
715 }
716
717 for (auto& series : time_series) {
718 series.second.label = GetStreamName(series.first);
719 series.second.style = LINE_GRAPH;
philipel35ba9bd2017-04-19 05:58:51 -0700720 plot->AppendTimeSeries(std::move(series.second));
ivocaac9d6f2016-09-22 07:01:47 -0700721 }
722
723 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
ivocbf676632016-11-24 08:30:34 -0800724 plot->SetYAxis(-127, 0, "Audio level (dBov)", kBottomMargin,
ivocaac9d6f2016-09-22 07:01:47 -0700725 kTopMargin);
726 plot->SetTitle("Audio level");
727}
728
terelius54ce6802016-07-13 06:44:41 -0700729// For each SSRC, plot the time between the consecutive playouts.
730void EventLogAnalyzer::CreateSequenceNumberGraph(Plot* plot) {
terelius6addf492016-08-23 17:34:07 -0700731 for (auto& kv : rtp_packets_) {
732 StreamId stream_id = kv.first;
733 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
734 // Filter on direction and SSRC.
735 if (stream_id.GetDirection() != kIncomingPacket ||
736 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
737 continue;
terelius54ce6802016-07-13 06:44:41 -0700738 }
terelius54ce6802016-07-13 06:44:41 -0700739
terelius23c595a2017-03-15 01:59:12 -0700740 TimeSeries time_series(GetStreamName(stream_id), BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700741 ProcessPairs<LoggedRtpPacket, float>(
742 [](const LoggedRtpPacket& old_packet,
743 const LoggedRtpPacket& new_packet) {
744 int64_t diff =
745 WrappingDifference(new_packet.header.sequenceNumber,
746 old_packet.header.sequenceNumber, 1ul << 16);
747 return rtc::Optional<float>(diff);
748 },
749 packet_stream, begin_time_, &time_series);
philipel35ba9bd2017-04-19 05:58:51 -0700750 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -0700751 }
752
tereliusdc35dcd2016-08-01 12:03:27 -0700753 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
754 plot->SetSuggestedYAxis(0, 1, "Difference since last packet", kBottomMargin,
755 kTopMargin);
756 plot->SetTitle("Sequence number");
terelius54ce6802016-07-13 06:44:41 -0700757}
758
Stefan Holmer99f8e082016-09-09 13:37:50 +0200759void EventLogAnalyzer::CreateIncomingPacketLossGraph(Plot* plot) {
760 for (auto& kv : rtp_packets_) {
761 StreamId stream_id = kv.first;
762 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
763 // Filter on direction and SSRC.
764 if (stream_id.GetDirection() != kIncomingPacket ||
terelius4c9b4af2017-01-30 08:44:51 -0800765 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
766 packet_stream.size() == 0) {
Stefan Holmer99f8e082016-09-09 13:37:50 +0200767 continue;
768 }
769
terelius23c595a2017-03-15 01:59:12 -0700770 TimeSeries time_series(GetStreamName(stream_id), LINE_DOT_GRAPH);
Stefan Holmer99f8e082016-09-09 13:37:50 +0200771 const uint64_t kWindowUs = 1000000;
terelius4c9b4af2017-01-30 08:44:51 -0800772 const uint64_t kStep = 1000000;
773 SequenceNumberUnwrapper unwrapper_;
774 SequenceNumberUnwrapper prior_unwrapper_;
775 size_t window_index_begin = 0;
776 size_t window_index_end = 0;
777 int64_t highest_seq_number =
778 unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
779 int64_t highest_prior_seq_number =
780 prior_unwrapper_.Unwrap(packet_stream[0].header.sequenceNumber) - 1;
781
782 for (uint64_t t = begin_time_; t < end_time_ + kStep; t += kStep) {
783 while (window_index_end < packet_stream.size() &&
784 packet_stream[window_index_end].timestamp < t) {
785 int64_t sequence_number = unwrapper_.Unwrap(
786 packet_stream[window_index_end].header.sequenceNumber);
787 highest_seq_number = std::max(highest_seq_number, sequence_number);
788 ++window_index_end;
Stefan Holmer99f8e082016-09-09 13:37:50 +0200789 }
terelius4c9b4af2017-01-30 08:44:51 -0800790 while (window_index_begin < packet_stream.size() &&
791 packet_stream[window_index_begin].timestamp < t - kWindowUs) {
792 int64_t sequence_number = prior_unwrapper_.Unwrap(
793 packet_stream[window_index_begin].header.sequenceNumber);
794 highest_prior_seq_number =
795 std::max(highest_prior_seq_number, sequence_number);
796 ++window_index_begin;
797 }
798 float x = static_cast<float>(t - begin_time_) / 1000000;
799 int64_t expected_packets = highest_seq_number - highest_prior_seq_number;
800 if (expected_packets > 0) {
801 int64_t received_packets = window_index_end - window_index_begin;
802 int64_t lost_packets = expected_packets - received_packets;
803 float y = static_cast<float>(lost_packets) / expected_packets * 100;
804 time_series.points.emplace_back(x, y);
805 }
Stefan Holmer99f8e082016-09-09 13:37:50 +0200806 }
philipel35ba9bd2017-04-19 05:58:51 -0700807 plot->AppendTimeSeries(std::move(time_series));
Stefan Holmer99f8e082016-09-09 13:37:50 +0200808 }
809
810 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
811 plot->SetSuggestedYAxis(0, 1, "Estimated loss rate (%)", kBottomMargin,
812 kTopMargin);
813 plot->SetTitle("Estimated incoming loss rate");
814}
815
terelius54ce6802016-07-13 06:44:41 -0700816void EventLogAnalyzer::CreateDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700817 for (auto& kv : rtp_packets_) {
818 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700819 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700820 // Filter on direction and SSRC.
821 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200822 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
823 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
824 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700825 continue;
826 }
terelius54ce6802016-07-13 06:44:41 -0700827
terelius23c595a2017-03-15 01:59:12 -0700828 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
829 BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700830 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
831 packet_stream, begin_time_,
832 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700833 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700834
terelius23c595a2017-03-15 01:59:12 -0700835 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
836 BAR_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700837 ProcessPairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
838 packet_stream, begin_time_,
839 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700840 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700841 }
842
tereliusdc35dcd2016-08-01 12:03:27 -0700843 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
844 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
845 kTopMargin);
846 plot->SetTitle("Network latency change between consecutive packets");
terelius54ce6802016-07-13 06:44:41 -0700847}
848
849void EventLogAnalyzer::CreateAccumulatedDelayChangeGraph(Plot* plot) {
terelius88e64e52016-07-19 01:51:06 -0700850 for (auto& kv : rtp_packets_) {
851 StreamId stream_id = kv.first;
tereliusccbbf8d2016-08-10 07:34:28 -0700852 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
terelius88e64e52016-07-19 01:51:06 -0700853 // Filter on direction and SSRC.
854 if (stream_id.GetDirection() != kIncomingPacket ||
Stefan Holmer99f8e082016-09-09 13:37:50 +0200855 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_) ||
856 IsAudioSsrc(stream_id) || !IsVideoSsrc(stream_id) ||
857 IsRtxSsrc(stream_id)) {
terelius88e64e52016-07-19 01:51:06 -0700858 continue;
859 }
terelius54ce6802016-07-13 06:44:41 -0700860
terelius23c595a2017-03-15 01:59:12 -0700861 TimeSeries capture_time_data(GetStreamName(stream_id) + " capture-time",
862 LINE_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700863 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_CaptureTime,
864 packet_stream, begin_time_,
865 &capture_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700866 plot->AppendTimeSeries(std::move(capture_time_data));
terelius88e64e52016-07-19 01:51:06 -0700867
terelius23c595a2017-03-15 01:59:12 -0700868 TimeSeries send_time_data(GetStreamName(stream_id) + " abs-send-time",
869 LINE_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -0700870 AccumulatePairs<LoggedRtpPacket, double>(NetworkDelayDiff_AbsSendTime,
871 packet_stream, begin_time_,
872 &send_time_data);
philipel35ba9bd2017-04-19 05:58:51 -0700873 plot->AppendTimeSeries(std::move(send_time_data));
terelius54ce6802016-07-13 06:44:41 -0700874 }
875
tereliusdc35dcd2016-08-01 12:03:27 -0700876 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
877 plot->SetSuggestedYAxis(0, 1, "Latency change (ms)", kBottomMargin,
878 kTopMargin);
879 plot->SetTitle("Accumulated network latency change");
terelius54ce6802016-07-13 06:44:41 -0700880}
881
tereliusf736d232016-08-04 10:00:11 -0700882// Plot the fraction of packets lost (as perceived by the loss-based BWE).
883void EventLogAnalyzer::CreateFractionLossGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -0700884 TimeSeries time_series("Fraction lost", LINE_DOT_GRAPH);
tereliusf736d232016-08-04 10:00:11 -0700885 for (auto& bwe_update : bwe_loss_updates_) {
886 float x = static_cast<float>(bwe_update.timestamp - begin_time_) / 1000000;
887 float y = static_cast<float>(bwe_update.fraction_loss) / 255 * 100;
philipel35ba9bd2017-04-19 05:58:51 -0700888 time_series.points.emplace_back(x, y);
tereliusf736d232016-08-04 10:00:11 -0700889 }
tereliusf736d232016-08-04 10:00:11 -0700890
891 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
892 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
893 kTopMargin);
894 plot->SetTitle("Reported packet loss");
philipel35ba9bd2017-04-19 05:58:51 -0700895 plot->AppendTimeSeries(std::move(time_series));
tereliusf736d232016-08-04 10:00:11 -0700896}
897
terelius54ce6802016-07-13 06:44:41 -0700898// Plot the total bandwidth used by all RTP streams.
899void EventLogAnalyzer::CreateTotalBitrateGraph(
900 PacketDirection desired_direction,
philipel23c7f252017-07-14 06:30:03 -0700901 Plot* plot,
902 bool show_detector_state) {
terelius54ce6802016-07-13 06:44:41 -0700903 struct TimestampSize {
904 TimestampSize(uint64_t t, size_t s) : timestamp(t), size(s) {}
905 uint64_t timestamp;
906 size_t size;
907 };
908 std::vector<TimestampSize> packets;
909
910 PacketDirection direction;
911 size_t total_length;
912
913 // Extract timestamps and sizes for the relevant packets.
914 for (size_t i = 0; i < parsed_log_.GetNumberOfEvents(); i++) {
915 ParsedRtcEventLog::EventType event_type = parsed_log_.GetEventType(i);
916 if (event_type == ParsedRtcEventLog::RTP_EVENT) {
perkj77cd58e2017-05-30 03:52:10 -0700917 parsed_log_.GetRtpHeader(i, &direction, nullptr, nullptr, &total_length);
terelius54ce6802016-07-13 06:44:41 -0700918 if (direction == desired_direction) {
919 uint64_t timestamp = parsed_log_.GetTimestamp(i);
920 packets.push_back(TimestampSize(timestamp, total_length));
921 }
922 }
923 }
924
925 size_t window_index_begin = 0;
926 size_t window_index_end = 0;
927 size_t bytes_in_window = 0;
terelius54ce6802016-07-13 06:44:41 -0700928
929 // Calculate a moving average of the bitrate and store in a TimeSeries.
philipel35ba9bd2017-04-19 05:58:51 -0700930 TimeSeries bitrate_series("Bitrate", LINE_GRAPH);
terelius54ce6802016-07-13 06:44:41 -0700931 for (uint64_t time = begin_time_; time < end_time_ + step_; time += step_) {
932 while (window_index_end < packets.size() &&
933 packets[window_index_end].timestamp < time) {
934 bytes_in_window += packets[window_index_end].size;
terelius6addf492016-08-23 17:34:07 -0700935 ++window_index_end;
terelius54ce6802016-07-13 06:44:41 -0700936 }
937 while (window_index_begin < packets.size() &&
938 packets[window_index_begin].timestamp < time - window_duration_) {
939 RTC_DCHECK_LE(packets[window_index_begin].size, bytes_in_window);
940 bytes_in_window -= packets[window_index_begin].size;
terelius6addf492016-08-23 17:34:07 -0700941 ++window_index_begin;
terelius54ce6802016-07-13 06:44:41 -0700942 }
943 float window_duration_in_seconds =
944 static_cast<float>(window_duration_) / 1000000;
945 float x = static_cast<float>(time - begin_time_) / 1000000;
946 float y = bytes_in_window * 8 / window_duration_in_seconds / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700947 bitrate_series.points.emplace_back(x, y);
terelius54ce6802016-07-13 06:44:41 -0700948 }
philipel35ba9bd2017-04-19 05:58:51 -0700949 plot->AppendTimeSeries(std::move(bitrate_series));
terelius54ce6802016-07-13 06:44:41 -0700950
terelius8058e582016-07-25 01:32:41 -0700951 // Overlay the send-side bandwidth estimate over the outgoing bitrate.
952 if (desired_direction == kOutgoingPacket) {
philipel35ba9bd2017-04-19 05:58:51 -0700953 TimeSeries loss_series("Loss-based estimate", LINE_STEP_GRAPH);
philipel10fc0e62017-04-11 01:50:23 -0700954 for (auto& loss_update : bwe_loss_updates_) {
terelius8058e582016-07-25 01:32:41 -0700955 float x =
philipel10fc0e62017-04-11 01:50:23 -0700956 static_cast<float>(loss_update.timestamp - begin_time_) / 1000000;
957 float y = static_cast<float>(loss_update.new_bitrate) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -0700958 loss_series.points.emplace_back(x, y);
philipel10fc0e62017-04-11 01:50:23 -0700959 }
960
philipel35ba9bd2017-04-19 05:58:51 -0700961 TimeSeries delay_series("Delay-based estimate", LINE_STEP_GRAPH);
philipel23c7f252017-07-14 06:30:03 -0700962 IntervalSeries overusing_series("Overusing", "#ff8e82",
963 IntervalSeries::kHorizontal);
964 IntervalSeries underusing_series("Underusing", "#5092fc",
965 IntervalSeries::kHorizontal);
966 IntervalSeries normal_series("Normal", "#c4ffc4",
967 IntervalSeries::kHorizontal);
968 IntervalSeries* last_series = &normal_series;
969 double last_detector_switch = 0.0;
970
971 BandwidthUsage last_detector_state = BandwidthUsage::kBwNormal;
972
philipel10fc0e62017-04-11 01:50:23 -0700973 for (auto& delay_update : bwe_delay_updates_) {
974 float x =
975 static_cast<float>(delay_update.timestamp - begin_time_) / 1000000;
976 float y = static_cast<float>(delay_update.bitrate_bps) / 1000;
philipel23c7f252017-07-14 06:30:03 -0700977
978 if (last_detector_state != delay_update.detector_state) {
979 last_series->intervals.emplace_back(last_detector_switch, x);
980 last_detector_state = delay_update.detector_state;
981 last_detector_switch = x;
982
983 switch (delay_update.detector_state) {
984 case BandwidthUsage::kBwNormal:
985 last_series = &normal_series;
986 break;
987 case BandwidthUsage::kBwUnderusing:
988 last_series = &underusing_series;
989 break;
990 case BandwidthUsage::kBwOverusing:
991 last_series = &overusing_series;
992 break;
993 }
994 }
995
philipel35ba9bd2017-04-19 05:58:51 -0700996 delay_series.points.emplace_back(x, y);
terelius8058e582016-07-25 01:32:41 -0700997 }
philipele127e7a2017-03-29 16:28:53 +0200998
philipel23c7f252017-07-14 06:30:03 -0700999 RTC_CHECK(last_series);
1000 last_series->intervals.emplace_back(last_detector_switch, end_time_);
1001
philipel35ba9bd2017-04-19 05:58:51 -07001002 TimeSeries created_series("Probe cluster created.", DOT_GRAPH);
philipele127e7a2017-03-29 16:28:53 +02001003 for (auto& cluster : bwe_probe_cluster_created_events_) {
1004 float x = static_cast<float>(cluster.timestamp - begin_time_) / 1000000;
1005 float y = static_cast<float>(cluster.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001006 created_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +02001007 }
1008
philipel35ba9bd2017-04-19 05:58:51 -07001009 TimeSeries result_series("Probing results.", DOT_GRAPH);
philipele127e7a2017-03-29 16:28:53 +02001010 for (auto& result : bwe_probe_result_events_) {
1011 if (result.bitrate_bps) {
1012 float x = static_cast<float>(result.timestamp - begin_time_) / 1000000;
1013 float y = static_cast<float>(*result.bitrate_bps) / 1000;
philipel35ba9bd2017-04-19 05:58:51 -07001014 result_series.points.emplace_back(x, y);
philipele127e7a2017-03-29 16:28:53 +02001015 }
1016 }
philipel23c7f252017-07-14 06:30:03 -07001017
1018 if (show_detector_state) {
1019 plot->AppendIntervalSeries(std::move(overusing_series));
1020 plot->AppendIntervalSeries(std::move(underusing_series));
1021 plot->AppendIntervalSeries(std::move(normal_series));
1022 }
1023
1024 plot->AppendTimeSeries(std::move(bitrate_series));
philipel35ba9bd2017-04-19 05:58:51 -07001025 plot->AppendTimeSeries(std::move(loss_series));
1026 plot->AppendTimeSeries(std::move(delay_series));
1027 plot->AppendTimeSeries(std::move(created_series));
1028 plot->AppendTimeSeries(std::move(result_series));
terelius8058e582016-07-25 01:32:41 -07001029 }
philipele127e7a2017-03-29 16:28:53 +02001030
terelius2c8e8a32017-06-02 01:29:48 -07001031 // Overlay the incoming REMB over the outgoing bitrate
1032 // and outgoing REMB over incoming bitrate.
1033 PacketDirection remb_direction =
1034 desired_direction == kOutgoingPacket ? kIncomingPacket : kOutgoingPacket;
1035 TimeSeries remb_series("Remb", LINE_STEP_GRAPH);
1036 std::multimap<uint64_t, const LoggedRtcpPacket*> remb_packets;
1037 for (const auto& kv : rtcp_packets_) {
1038 if (kv.first.GetDirection() == remb_direction) {
1039 for (const LoggedRtcpPacket& rtcp_packet : kv.second) {
1040 if (rtcp_packet.type == kRtcpRemb) {
1041 remb_packets.insert(
1042 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1043 }
1044 }
1045 }
1046 }
1047
1048 for (const auto& kv : remb_packets) {
1049 const LoggedRtcpPacket* const rtcp = kv.second;
1050 const rtcp::Remb* const remb = static_cast<rtcp::Remb*>(rtcp->packet.get());
1051 float x = static_cast<float>(rtcp->timestamp - begin_time_) / 1000000;
1052 float y = static_cast<float>(remb->bitrate_bps()) / 1000;
1053 remb_series.points.emplace_back(x, y);
1054 }
1055 plot->AppendTimeSeriesIfNotEmpty(std::move(remb_series));
1056
tereliusdc35dcd2016-08-01 12:03:27 -07001057 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1058 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001059 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001060 plot->SetTitle("Incoming RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001061 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001062 plot->SetTitle("Outgoing RTP bitrate");
terelius54ce6802016-07-13 06:44:41 -07001063 }
1064}
1065
1066// For each SSRC, plot the bandwidth used by that stream.
1067void EventLogAnalyzer::CreateStreamBitrateGraph(
1068 PacketDirection desired_direction,
1069 Plot* plot) {
terelius6addf492016-08-23 17:34:07 -07001070 for (auto& kv : rtp_packets_) {
1071 StreamId stream_id = kv.first;
1072 const std::vector<LoggedRtpPacket>& packet_stream = kv.second;
1073 // Filter on direction and SSRC.
1074 if (stream_id.GetDirection() != desired_direction ||
1075 !MatchingSsrc(stream_id.GetSsrc(), desired_ssrc_)) {
1076 continue;
terelius54ce6802016-07-13 06:44:41 -07001077 }
1078
terelius23c595a2017-03-15 01:59:12 -07001079 TimeSeries time_series(GetStreamName(stream_id), LINE_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001080 MovingAverage<LoggedRtpPacket, double>(
1081 [](const LoggedRtpPacket& packet) {
1082 return rtc::Optional<double>(packet.total_length * 8.0 / 1000.0);
1083 },
1084 packet_stream, begin_time_, end_time_, window_duration_, step_,
1085 &time_series);
philipel35ba9bd2017-04-19 05:58:51 -07001086 plot->AppendTimeSeries(std::move(time_series));
terelius54ce6802016-07-13 06:44:41 -07001087 }
1088
tereliusdc35dcd2016-08-01 12:03:27 -07001089 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1090 plot->SetSuggestedYAxis(0, 1, "Bitrate (kbps)", kBottomMargin, kTopMargin);
terelius54ce6802016-07-13 06:44:41 -07001091 if (desired_direction == webrtc::PacketDirection::kIncomingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001092 plot->SetTitle("Incoming bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001093 } else if (desired_direction == webrtc::PacketDirection::kOutgoingPacket) {
tereliusdc35dcd2016-08-01 12:03:27 -07001094 plot->SetTitle("Outgoing bitrate per stream");
terelius54ce6802016-07-13 06:44:41 -07001095 }
1096}
1097
tereliuse34c19c2016-08-15 08:47:14 -07001098void EventLogAnalyzer::CreateBweSimulationGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001099 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1100 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
Stefan Holmer13181032016-07-29 14:48:54 +02001101
1102 for (const auto& kv : rtp_packets_) {
1103 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1104 for (const LoggedRtpPacket& rtp_packet : kv.second)
1105 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1106 }
1107 }
1108
1109 for (const auto& kv : rtcp_packets_) {
1110 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1111 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1112 incoming_rtcp.insert(
1113 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1114 }
1115 }
1116
1117 SimulatedClock clock(0);
1118 BitrateObserver observer;
1119 RtcEventLogNullImpl null_event_log;
nisse0245da02016-11-30 03:35:20 -08001120 PacketRouter packet_router;
1121 CongestionController cc(&clock, &observer, &observer, &null_event_log,
1122 &packet_router);
Stefan Holmer13181032016-07-29 14:48:54 +02001123 // TODO(holmer): Log the call config and use that here instead.
1124 static const uint32_t kDefaultStartBitrateBps = 300000;
1125 cc.SetBweBitrates(0, kDefaultStartBitrateBps, -1);
1126
terelius23c595a2017-03-15 01:59:12 -07001127 TimeSeries time_series("Delay-based estimate", LINE_DOT_GRAPH);
1128 TimeSeries acked_time_series("Acked bitrate", LINE_DOT_GRAPH);
Stefan Holmer13181032016-07-29 14:48:54 +02001129
1130 auto rtp_iterator = outgoing_rtp.begin();
1131 auto rtcp_iterator = incoming_rtcp.begin();
1132
1133 auto NextRtpTime = [&]() {
1134 if (rtp_iterator != outgoing_rtp.end())
1135 return static_cast<int64_t>(rtp_iterator->first);
1136 return std::numeric_limits<int64_t>::max();
1137 };
1138
1139 auto NextRtcpTime = [&]() {
1140 if (rtcp_iterator != incoming_rtcp.end())
1141 return static_cast<int64_t>(rtcp_iterator->first);
1142 return std::numeric_limits<int64_t>::max();
1143 };
1144
1145 auto NextProcessTime = [&]() {
1146 if (rtcp_iterator != incoming_rtcp.end() ||
1147 rtp_iterator != outgoing_rtp.end()) {
1148 return clock.TimeInMicroseconds() +
1149 std::max<int64_t>(cc.TimeUntilNextProcess() * 1000, 0);
1150 }
1151 return std::numeric_limits<int64_t>::max();
1152 };
1153
Stefan Holmer492ee282016-10-27 17:19:20 +02001154 RateStatistics acked_bitrate(250, 8000);
Stefan Holmer60e43462016-09-07 09:58:20 +02001155
Stefan Holmer13181032016-07-29 14:48:54 +02001156 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
Stefan Holmer492ee282016-10-27 17:19:20 +02001157 int64_t last_update_us = 0;
Stefan Holmer13181032016-07-29 14:48:54 +02001158 while (time_us != std::numeric_limits<int64_t>::max()) {
1159 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1160 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001161 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001162 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1163 if (rtcp.type == kRtcpTransportFeedback) {
elad.alon5bbf43f2017-03-09 06:40:08 -08001164 cc.OnTransportFeedback(
1165 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
1166 std::vector<PacketFeedback> feedback = cc.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001167 SortPacketFeedbackVector(&feedback);
Stefan Holmer60e43462016-09-07 09:58:20 +02001168 rtc::Optional<uint32_t> bitrate_bps;
1169 if (!feedback.empty()) {
elad.alonf9490002017-03-06 05:32:21 -08001170 for (const PacketFeedback& packet : feedback)
Stefan Holmer60e43462016-09-07 09:58:20 +02001171 acked_bitrate.Update(packet.payload_size, packet.arrival_time_ms);
1172 bitrate_bps = acked_bitrate.Rate(feedback.back().arrival_time_ms);
1173 }
1174 uint32_t y = 0;
1175 if (bitrate_bps)
1176 y = *bitrate_bps / 1000;
1177 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1178 1000000;
1179 acked_time_series.points.emplace_back(x, y);
Stefan Holmer13181032016-07-29 14:48:54 +02001180 }
1181 ++rtcp_iterator;
1182 }
1183 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
stefanc3de0332016-08-02 07:22:17 -07001184 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001185 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1186 if (rtp.header.extension.hasTransportSequenceNumber) {
1187 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001188 cc.AddPacket(rtp.header.ssrc,
1189 rtp.header.extension.transportSequenceNumber,
elad.alon5bbf43f2017-03-09 06:40:08 -08001190 rtp.total_length, PacedPacketInfo());
Stefan Holmer13181032016-07-29 14:48:54 +02001191 rtc::SentPacket sent_packet(
1192 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1193 cc.OnSentPacket(sent_packet);
1194 }
1195 ++rtp_iterator;
1196 }
stefanc3de0332016-08-02 07:22:17 -07001197 if (clock.TimeInMicroseconds() >= NextProcessTime()) {
1198 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextProcessTime());
Stefan Holmer13181032016-07-29 14:48:54 +02001199 cc.Process();
stefanc3de0332016-08-02 07:22:17 -07001200 }
Stefan Holmer492ee282016-10-27 17:19:20 +02001201 if (observer.GetAndResetBitrateUpdated() ||
1202 time_us - last_update_us >= 1e6) {
Stefan Holmer13181032016-07-29 14:48:54 +02001203 uint32_t y = observer.last_bitrate_bps() / 1000;
Stefan Holmer13181032016-07-29 14:48:54 +02001204 float x = static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1205 1000000;
1206 time_series.points.emplace_back(x, y);
Stefan Holmer492ee282016-10-27 17:19:20 +02001207 last_update_us = time_us;
Stefan Holmer13181032016-07-29 14:48:54 +02001208 }
1209 time_us = std::min({NextRtpTime(), NextRtcpTime(), NextProcessTime()});
1210 }
1211 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001212 plot->AppendTimeSeries(std::move(time_series));
1213 plot->AppendTimeSeries(std::move(acked_time_series));
Stefan Holmer13181032016-07-29 14:48:54 +02001214
tereliusdc35dcd2016-08-01 12:03:27 -07001215 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1216 plot->SetSuggestedYAxis(0, 10, "Bitrate (kbps)", kBottomMargin, kTopMargin);
1217 plot->SetTitle("Simulated BWE behavior");
Stefan Holmer13181032016-07-29 14:48:54 +02001218}
1219
tereliuse34c19c2016-08-15 08:47:14 -07001220void EventLogAnalyzer::CreateNetworkDelayFeedbackGraph(Plot* plot) {
stefanff421622017-04-20 03:24:01 -07001221 std::multimap<uint64_t, const LoggedRtpPacket*> outgoing_rtp;
1222 std::multimap<uint64_t, const LoggedRtcpPacket*> incoming_rtcp;
stefanc3de0332016-08-02 07:22:17 -07001223
1224 for (const auto& kv : rtp_packets_) {
1225 if (kv.first.GetDirection() == PacketDirection::kOutgoingPacket) {
1226 for (const LoggedRtpPacket& rtp_packet : kv.second)
1227 outgoing_rtp.insert(std::make_pair(rtp_packet.timestamp, &rtp_packet));
1228 }
1229 }
1230
1231 for (const auto& kv : rtcp_packets_) {
1232 if (kv.first.GetDirection() == PacketDirection::kIncomingPacket) {
1233 for (const LoggedRtcpPacket& rtcp_packet : kv.second)
1234 incoming_rtcp.insert(
1235 std::make_pair(rtcp_packet.timestamp, &rtcp_packet));
1236 }
1237 }
1238
1239 SimulatedClock clock(0);
elad.alon5bbf43f2017-03-09 06:40:08 -08001240 TransportFeedbackAdapter feedback_adapter(&clock);
stefanc3de0332016-08-02 07:22:17 -07001241
terelius23c595a2017-03-15 01:59:12 -07001242 TimeSeries time_series("Network Delay Change", LINE_DOT_GRAPH);
stefanc3de0332016-08-02 07:22:17 -07001243 int64_t estimated_base_delay_ms = std::numeric_limits<int64_t>::max();
1244
1245 auto rtp_iterator = outgoing_rtp.begin();
1246 auto rtcp_iterator = incoming_rtcp.begin();
1247
1248 auto NextRtpTime = [&]() {
1249 if (rtp_iterator != outgoing_rtp.end())
1250 return static_cast<int64_t>(rtp_iterator->first);
1251 return std::numeric_limits<int64_t>::max();
1252 };
1253
1254 auto NextRtcpTime = [&]() {
1255 if (rtcp_iterator != incoming_rtcp.end())
1256 return static_cast<int64_t>(rtcp_iterator->first);
1257 return std::numeric_limits<int64_t>::max();
1258 };
1259
1260 int64_t time_us = std::min(NextRtpTime(), NextRtcpTime());
1261 while (time_us != std::numeric_limits<int64_t>::max()) {
1262 clock.AdvanceTimeMicroseconds(time_us - clock.TimeInMicroseconds());
1263 if (clock.TimeInMicroseconds() >= NextRtcpTime()) {
1264 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtcpTime());
1265 const LoggedRtcpPacket& rtcp = *rtcp_iterator->second;
1266 if (rtcp.type == kRtcpTransportFeedback) {
Stefan Holmer60e43462016-09-07 09:58:20 +02001267 feedback_adapter.OnTransportFeedback(
1268 *static_cast<rtcp::TransportFeedback*>(rtcp.packet.get()));
elad.alonf9490002017-03-06 05:32:21 -08001269 std::vector<PacketFeedback> feedback =
1270 feedback_adapter.GetTransportFeedbackVector();
elad.alonec304f92017-03-08 05:03:53 -08001271 SortPacketFeedbackVector(&feedback);
elad.alonf9490002017-03-06 05:32:21 -08001272 for (const PacketFeedback& packet : feedback) {
stefanc3de0332016-08-02 07:22:17 -07001273 int64_t y = packet.arrival_time_ms - packet.send_time_ms;
1274 float x =
1275 static_cast<float>(clock.TimeInMicroseconds() - begin_time_) /
1276 1000000;
1277 estimated_base_delay_ms = std::min(y, estimated_base_delay_ms);
1278 time_series.points.emplace_back(x, y);
1279 }
1280 }
1281 ++rtcp_iterator;
1282 }
1283 if (clock.TimeInMicroseconds() >= NextRtpTime()) {
1284 RTC_DCHECK_EQ(clock.TimeInMicroseconds(), NextRtpTime());
1285 const LoggedRtpPacket& rtp = *rtp_iterator->second;
1286 if (rtp.header.extension.hasTransportSequenceNumber) {
1287 RTC_DCHECK(rtp.header.extension.hasTransportSequenceNumber);
elad.alond12a8e12017-03-23 11:04:48 -07001288 feedback_adapter.AddPacket(rtp.header.ssrc,
1289 rtp.header.extension.transportSequenceNumber,
philipel8aadd502017-02-23 02:56:13 -08001290 rtp.total_length, PacedPacketInfo());
stefanc3de0332016-08-02 07:22:17 -07001291 feedback_adapter.OnSentPacket(
1292 rtp.header.extension.transportSequenceNumber, rtp.timestamp / 1000);
1293 }
1294 ++rtp_iterator;
1295 }
1296 time_us = std::min(NextRtpTime(), NextRtcpTime());
1297 }
1298 // We assume that the base network delay (w/o queues) is the min delay
1299 // observed during the call.
1300 for (TimeSeriesPoint& point : time_series.points)
1301 point.y -= estimated_base_delay_ms;
1302 // Add the data set to the plot.
philipel35ba9bd2017-04-19 05:58:51 -07001303 plot->AppendTimeSeries(std::move(time_series));
stefanc3de0332016-08-02 07:22:17 -07001304
1305 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1306 plot->SetSuggestedYAxis(0, 10, "Delay (ms)", kBottomMargin, kTopMargin);
1307 plot->SetTitle("Network Delay Change.");
1308}
stefan08383272016-12-20 08:51:52 -08001309
1310std::vector<std::pair<int64_t, int64_t>> EventLogAnalyzer::GetFrameTimestamps()
1311 const {
1312 std::vector<std::pair<int64_t, int64_t>> timestamps;
1313 size_t largest_stream_size = 0;
1314 const std::vector<LoggedRtpPacket>* largest_video_stream = nullptr;
1315 // Find the incoming video stream with the most number of packets that is
1316 // not rtx.
1317 for (const auto& kv : rtp_packets_) {
1318 if (kv.first.GetDirection() == kIncomingPacket &&
1319 video_ssrcs_.find(kv.first) != video_ssrcs_.end() &&
1320 rtx_ssrcs_.find(kv.first) == rtx_ssrcs_.end() &&
1321 kv.second.size() > largest_stream_size) {
1322 largest_stream_size = kv.second.size();
1323 largest_video_stream = &kv.second;
1324 }
1325 }
1326 if (largest_video_stream == nullptr) {
1327 for (auto& packet : *largest_video_stream) {
1328 if (packet.header.markerBit) {
1329 int64_t capture_ms = packet.header.timestamp / 90.0;
1330 int64_t arrival_ms = packet.timestamp / 1000.0;
1331 timestamps.push_back(std::make_pair(capture_ms, arrival_ms));
1332 }
1333 }
1334 }
1335 return timestamps;
1336}
stefane372d3c2017-02-02 08:04:18 -08001337
1338void EventLogAnalyzer::CreateTimestampGraph(Plot* plot) {
1339 for (const auto& kv : rtp_packets_) {
1340 const std::vector<LoggedRtpPacket>& rtp_packets = kv.second;
1341 StreamId stream_id = kv.first;
1342
1343 {
terelius23c595a2017-03-15 01:59:12 -07001344 TimeSeries timestamp_data(GetStreamName(stream_id) + " capture-time",
1345 LINE_DOT_GRAPH);
stefane372d3c2017-02-02 08:04:18 -08001346 for (LoggedRtpPacket packet : rtp_packets) {
1347 float x = static_cast<float>(packet.timestamp - begin_time_) / 1000000;
1348 float y = packet.header.timestamp;
1349 timestamp_data.points.emplace_back(x, y);
1350 }
philipel35ba9bd2017-04-19 05:58:51 -07001351 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001352 }
1353
1354 {
1355 auto kv = rtcp_packets_.find(stream_id);
1356 if (kv != rtcp_packets_.end()) {
1357 const auto& packets = kv->second;
terelius23c595a2017-03-15 01:59:12 -07001358 TimeSeries timestamp_data(
1359 GetStreamName(stream_id) + " rtcp capture-time", LINE_DOT_GRAPH);
stefane372d3c2017-02-02 08:04:18 -08001360 for (const LoggedRtcpPacket& rtcp : packets) {
1361 if (rtcp.type != kRtcpSr)
1362 continue;
1363 rtcp::SenderReport* sr;
1364 sr = static_cast<rtcp::SenderReport*>(rtcp.packet.get());
1365 float x = static_cast<float>(rtcp.timestamp - begin_time_) / 1000000;
1366 float y = sr->rtp_timestamp();
1367 timestamp_data.points.emplace_back(x, y);
1368 }
philipel35ba9bd2017-04-19 05:58:51 -07001369 plot->AppendTimeSeries(std::move(timestamp_data));
stefane372d3c2017-02-02 08:04:18 -08001370 }
1371 }
1372 }
1373
1374 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1375 plot->SetSuggestedYAxis(0, 1, "Timestamp (90khz)", kBottomMargin, kTopMargin);
1376 plot->SetTitle("Timestamps");
1377}
michaelt6e5b2192017-02-22 07:33:27 -08001378
1379void EventLogAnalyzer::CreateAudioEncoderTargetBitrateGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001380 TimeSeries time_series("Audio encoder target bitrate", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001381 ProcessPoints<AudioNetworkAdaptationEvent>(
1382 [](const AudioNetworkAdaptationEvent& ana_event) -> rtc::Optional<float> {
michaelt6e5b2192017-02-22 07:33:27 -08001383 if (ana_event.config.bitrate_bps)
1384 return rtc::Optional<float>(
1385 static_cast<float>(*ana_event.config.bitrate_bps));
1386 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001387 },
philipel35ba9bd2017-04-19 05:58:51 -07001388 audio_network_adaptation_events_, begin_time_, &time_series);
1389 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001390 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1391 plot->SetSuggestedYAxis(0, 1, "Bitrate (bps)", kBottomMargin, kTopMargin);
1392 plot->SetTitle("Reported audio encoder target bitrate");
1393}
1394
1395void EventLogAnalyzer::CreateAudioEncoderFrameLengthGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001396 TimeSeries time_series("Audio encoder frame length", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001397 ProcessPoints<AudioNetworkAdaptationEvent>(
1398 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001399 if (ana_event.config.frame_length_ms)
1400 return rtc::Optional<float>(
1401 static_cast<float>(*ana_event.config.frame_length_ms));
1402 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001403 },
philipel35ba9bd2017-04-19 05:58:51 -07001404 audio_network_adaptation_events_, begin_time_, &time_series);
1405 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001406 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1407 plot->SetSuggestedYAxis(0, 1, "Frame length (ms)", kBottomMargin, kTopMargin);
1408 plot->SetTitle("Reported audio encoder frame length");
1409}
1410
1411void EventLogAnalyzer::CreateAudioEncoderUplinkPacketLossFractionGraph(
1412 Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001413 TimeSeries time_series("Audio encoder uplink packet loss fraction",
1414 LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001415 ProcessPoints<AudioNetworkAdaptationEvent>(
1416 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001417 if (ana_event.config.uplink_packet_loss_fraction)
1418 return rtc::Optional<float>(static_cast<float>(
1419 *ana_event.config.uplink_packet_loss_fraction));
1420 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001421 },
philipel35ba9bd2017-04-19 05:58:51 -07001422 audio_network_adaptation_events_, begin_time_, &time_series);
1423 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001424 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1425 plot->SetSuggestedYAxis(0, 10, "Percent lost packets", kBottomMargin,
1426 kTopMargin);
1427 plot->SetTitle("Reported audio encoder lost packets");
1428}
1429
1430void EventLogAnalyzer::CreateAudioEncoderEnableFecGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001431 TimeSeries time_series("Audio encoder FEC", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001432 ProcessPoints<AudioNetworkAdaptationEvent>(
1433 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001434 if (ana_event.config.enable_fec)
1435 return rtc::Optional<float>(
1436 static_cast<float>(*ana_event.config.enable_fec));
1437 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001438 },
philipel35ba9bd2017-04-19 05:58:51 -07001439 audio_network_adaptation_events_, begin_time_, &time_series);
1440 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001441 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1442 plot->SetSuggestedYAxis(0, 1, "FEC (false/true)", kBottomMargin, kTopMargin);
1443 plot->SetTitle("Reported audio encoder FEC");
1444}
1445
1446void EventLogAnalyzer::CreateAudioEncoderEnableDtxGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001447 TimeSeries time_series("Audio encoder DTX", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001448 ProcessPoints<AudioNetworkAdaptationEvent>(
1449 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001450 if (ana_event.config.enable_dtx)
1451 return rtc::Optional<float>(
1452 static_cast<float>(*ana_event.config.enable_dtx));
1453 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001454 },
philipel35ba9bd2017-04-19 05:58:51 -07001455 audio_network_adaptation_events_, begin_time_, &time_series);
1456 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001457 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1458 plot->SetSuggestedYAxis(0, 1, "DTX (false/true)", kBottomMargin, kTopMargin);
1459 plot->SetTitle("Reported audio encoder DTX");
1460}
1461
1462void EventLogAnalyzer::CreateAudioEncoderNumChannelsGraph(Plot* plot) {
philipel35ba9bd2017-04-19 05:58:51 -07001463 TimeSeries time_series("Audio encoder number of channels", LINE_DOT_GRAPH);
terelius53dc23c2017-03-13 05:24:05 -07001464 ProcessPoints<AudioNetworkAdaptationEvent>(
1465 [](const AudioNetworkAdaptationEvent& ana_event) {
michaelt6e5b2192017-02-22 07:33:27 -08001466 if (ana_event.config.num_channels)
1467 return rtc::Optional<float>(
1468 static_cast<float>(*ana_event.config.num_channels));
1469 return rtc::Optional<float>();
terelius53dc23c2017-03-13 05:24:05 -07001470 },
philipel35ba9bd2017-04-19 05:58:51 -07001471 audio_network_adaptation_events_, begin_time_, &time_series);
1472 plot->AppendTimeSeries(std::move(time_series));
michaelt6e5b2192017-02-22 07:33:27 -08001473 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1474 plot->SetSuggestedYAxis(0, 1, "Number of channels (1 (mono)/2 (stereo))",
1475 kBottomMargin, kTopMargin);
1476 plot->SetTitle("Reported audio encoder number of channels");
1477}
henrik.lundin3c938fc2017-06-14 06:09:58 -07001478
1479class NetEqStreamInput : public test::NetEqInput {
1480 public:
1481 // Does not take any ownership, and all pointers must refer to valid objects
1482 // that outlive the one constructed.
1483 NetEqStreamInput(const std::vector<LoggedRtpPacket>* packet_stream,
1484 const std::vector<uint64_t>* output_events_us,
1485 rtc::Optional<uint64_t> end_time_us)
1486 : packet_stream_(*packet_stream),
1487 packet_stream_it_(packet_stream_.begin()),
1488 output_events_us_it_(output_events_us->begin()),
1489 output_events_us_end_(output_events_us->end()),
1490 end_time_us_(end_time_us) {
1491 RTC_DCHECK(packet_stream);
1492 RTC_DCHECK(output_events_us);
1493 }
1494
1495 rtc::Optional<int64_t> NextPacketTime() const override {
1496 if (packet_stream_it_ == packet_stream_.end()) {
1497 return rtc::Optional<int64_t>();
1498 }
1499 if (end_time_us_ && packet_stream_it_->timestamp > *end_time_us_) {
1500 return rtc::Optional<int64_t>();
1501 }
1502 // Convert from us to ms.
1503 return rtc::Optional<int64_t>(packet_stream_it_->timestamp / 1000);
1504 }
1505
1506 rtc::Optional<int64_t> NextOutputEventTime() const override {
1507 if (output_events_us_it_ == output_events_us_end_) {
1508 return rtc::Optional<int64_t>();
1509 }
1510 if (end_time_us_ && *output_events_us_it_ > *end_time_us_) {
1511 return rtc::Optional<int64_t>();
1512 }
1513 // Convert from us to ms.
1514 return rtc::Optional<int64_t>(
1515 rtc::checked_cast<int64_t>(*output_events_us_it_ / 1000));
1516 }
1517
1518 std::unique_ptr<PacketData> PopPacket() override {
1519 if (packet_stream_it_ == packet_stream_.end()) {
1520 return std::unique_ptr<PacketData>();
1521 }
1522 std::unique_ptr<PacketData> packet_data(new PacketData());
1523 packet_data->header = packet_stream_it_->header;
1524 // Convert from us to ms.
1525 packet_data->time_ms = packet_stream_it_->timestamp / 1000.0;
1526
1527 // This is a header-only "dummy" packet. Set the payload to all zeros, with
1528 // length according to the virtual length.
1529 packet_data->payload.SetSize(packet_stream_it_->total_length);
1530 std::fill_n(packet_data->payload.data(), packet_data->payload.size(), 0);
1531
1532 ++packet_stream_it_;
1533 return packet_data;
1534 }
1535
1536 void AdvanceOutputEvent() override {
1537 if (output_events_us_it_ != output_events_us_end_) {
1538 ++output_events_us_it_;
1539 }
1540 }
1541
1542 bool ended() const override { return !NextEventTime(); }
1543
1544 rtc::Optional<RTPHeader> NextHeader() const override {
1545 if (packet_stream_it_ == packet_stream_.end()) {
1546 return rtc::Optional<RTPHeader>();
1547 }
1548 return rtc::Optional<RTPHeader>(packet_stream_it_->header);
1549 }
1550
1551 private:
1552 const std::vector<LoggedRtpPacket>& packet_stream_;
1553 std::vector<LoggedRtpPacket>::const_iterator packet_stream_it_;
1554 std::vector<uint64_t>::const_iterator output_events_us_it_;
1555 const std::vector<uint64_t>::const_iterator output_events_us_end_;
1556 const rtc::Optional<uint64_t> end_time_us_;
1557};
1558
1559namespace {
1560// Creates a NetEq test object and all necessary input and output helpers. Runs
1561// the test and returns the NetEqDelayAnalyzer object that was used to
1562// instrument the test.
1563std::unique_ptr<test::NetEqDelayAnalyzer> CreateNetEqTestAndRun(
1564 const std::vector<LoggedRtpPacket>* packet_stream,
1565 const std::vector<uint64_t>* output_events_us,
1566 rtc::Optional<uint64_t> end_time_us,
1567 const std::string& replacement_file_name,
1568 int file_sample_rate_hz) {
1569 std::unique_ptr<test::NetEqInput> input(
1570 new NetEqStreamInput(packet_stream, output_events_us, end_time_us));
1571
1572 constexpr int kReplacementPt = 127;
1573 std::set<uint8_t> cn_types;
1574 std::set<uint8_t> forbidden_types;
1575 input.reset(new test::NetEqReplacementInput(std::move(input), kReplacementPt,
1576 cn_types, forbidden_types));
1577
1578 NetEq::Config config;
1579 config.max_packets_in_buffer = 200;
1580 config.enable_fast_accelerate = true;
1581
1582 std::unique_ptr<test::VoidAudioSink> output(new test::VoidAudioSink());
1583
1584 test::NetEqTest::DecoderMap codecs;
1585
1586 // Create a "replacement decoder" that produces the decoded audio by reading
1587 // from a file rather than from the encoded payloads.
1588 std::unique_ptr<test::ResampleInputAudioFile> replacement_file(
1589 new test::ResampleInputAudioFile(replacement_file_name,
1590 file_sample_rate_hz));
1591 replacement_file->set_output_rate_hz(48000);
1592 std::unique_ptr<AudioDecoder> replacement_decoder(
1593 new test::FakeDecodeFromFile(std::move(replacement_file), 48000, false));
1594 test::NetEqTest::ExtDecoderMap ext_codecs;
1595 ext_codecs[kReplacementPt] = {replacement_decoder.get(),
1596 NetEqDecoder::kDecoderArbitrary,
1597 "replacement codec"};
1598
1599 std::unique_ptr<test::NetEqDelayAnalyzer> delay_cb(
1600 new test::NetEqDelayAnalyzer);
1601 test::DefaultNetEqTestErrorCallback error_cb;
1602 test::NetEqTest::Callbacks callbacks;
1603 callbacks.error_callback = &error_cb;
1604 callbacks.post_insert_packet = delay_cb.get();
1605 callbacks.get_audio_callback = delay_cb.get();
1606
1607 test::NetEqTest test(config, codecs, ext_codecs, std::move(input),
1608 std::move(output), callbacks);
1609 test.Run();
1610 return delay_cb;
1611}
1612} // namespace
1613
1614// Plots the jitter buffer delay profile. This will plot only for the first
1615// incoming audio SSRC. If the stream contains more than one incoming audio
1616// SSRC, all but the first will be ignored.
1617void EventLogAnalyzer::CreateAudioJitterBufferGraph(
1618 const std::string& replacement_file_name,
1619 int file_sample_rate_hz,
1620 Plot* plot) {
1621 const auto& incoming_audio_kv = std::find_if(
1622 rtp_packets_.begin(), rtp_packets_.end(),
1623 [this](std::pair<StreamId, std::vector<LoggedRtpPacket>> kv) {
1624 return kv.first.GetDirection() == kIncomingPacket &&
1625 this->IsAudioSsrc(kv.first);
1626 });
1627 if (incoming_audio_kv == rtp_packets_.end()) {
1628 // No incoming audio stream found.
1629 return;
1630 }
1631
1632 const uint32_t ssrc = incoming_audio_kv->first.GetSsrc();
1633
1634 std::map<uint32_t, std::vector<uint64_t>>::const_iterator output_events_it =
1635 audio_playout_events_.find(ssrc);
1636 if (output_events_it == audio_playout_events_.end()) {
1637 // Could not find output events with SSRC matching the input audio stream.
1638 // Using the first available stream of output events.
1639 output_events_it = audio_playout_events_.cbegin();
1640 }
1641
1642 rtc::Optional<uint64_t> end_time_us =
1643 log_segments_.empty()
1644 ? rtc::Optional<uint64_t>()
1645 : rtc::Optional<uint64_t>(log_segments_.front().second);
1646
1647 auto delay_cb = CreateNetEqTestAndRun(
1648 &incoming_audio_kv->second, &output_events_it->second, end_time_us,
1649 replacement_file_name, file_sample_rate_hz);
1650
1651 std::vector<float> send_times_s;
1652 std::vector<float> arrival_delay_ms;
1653 std::vector<float> corrected_arrival_delay_ms;
1654 std::vector<rtc::Optional<float>> playout_delay_ms;
1655 std::vector<rtc::Optional<float>> target_delay_ms;
1656 delay_cb->CreateGraphs(&send_times_s, &arrival_delay_ms,
1657 &corrected_arrival_delay_ms, &playout_delay_ms,
1658 &target_delay_ms);
1659 RTC_DCHECK_EQ(send_times_s.size(), arrival_delay_ms.size());
1660 RTC_DCHECK_EQ(send_times_s.size(), corrected_arrival_delay_ms.size());
1661 RTC_DCHECK_EQ(send_times_s.size(), playout_delay_ms.size());
1662 RTC_DCHECK_EQ(send_times_s.size(), target_delay_ms.size());
1663
1664 std::map<StreamId, TimeSeries> time_series_packet_arrival;
1665 std::map<StreamId, TimeSeries> time_series_relative_packet_arrival;
1666 std::map<StreamId, TimeSeries> time_series_play_time;
1667 std::map<StreamId, TimeSeries> time_series_target_time;
1668 float min_y_axis = 0.f;
1669 float max_y_axis = 0.f;
1670 const StreamId stream_id = incoming_audio_kv->first;
1671 for (size_t i = 0; i < send_times_s.size(); ++i) {
1672 time_series_packet_arrival[stream_id].points.emplace_back(
1673 TimeSeriesPoint(send_times_s[i], arrival_delay_ms[i]));
1674 time_series_relative_packet_arrival[stream_id].points.emplace_back(
1675 TimeSeriesPoint(send_times_s[i], corrected_arrival_delay_ms[i]));
1676 min_y_axis = std::min(min_y_axis, corrected_arrival_delay_ms[i]);
1677 max_y_axis = std::max(max_y_axis, corrected_arrival_delay_ms[i]);
1678 if (playout_delay_ms[i]) {
1679 time_series_play_time[stream_id].points.emplace_back(
1680 TimeSeriesPoint(send_times_s[i], *playout_delay_ms[i]));
1681 min_y_axis = std::min(min_y_axis, *playout_delay_ms[i]);
1682 max_y_axis = std::max(max_y_axis, *playout_delay_ms[i]);
1683 }
1684 if (target_delay_ms[i]) {
1685 time_series_target_time[stream_id].points.emplace_back(
1686 TimeSeriesPoint(send_times_s[i], *target_delay_ms[i]));
1687 min_y_axis = std::min(min_y_axis, *target_delay_ms[i]);
1688 max_y_axis = std::max(max_y_axis, *target_delay_ms[i]);
1689 }
1690 }
1691
1692 // This code is adapted for a single stream. The creation of the streams above
1693 // guarantee that no more than one steam is included. If multiple streams are
1694 // to be plotted, they should likely be given distinct labels below.
1695 RTC_DCHECK_EQ(time_series_relative_packet_arrival.size(), 1);
1696 for (auto& series : time_series_relative_packet_arrival) {
1697 series.second.label = "Relative packet arrival delay";
1698 series.second.style = LINE_GRAPH;
1699 plot->AppendTimeSeries(std::move(series.second));
1700 }
1701 RTC_DCHECK_EQ(time_series_play_time.size(), 1);
1702 for (auto& series : time_series_play_time) {
1703 series.second.label = "Playout delay";
1704 series.second.style = LINE_GRAPH;
1705 plot->AppendTimeSeries(std::move(series.second));
1706 }
1707 RTC_DCHECK_EQ(time_series_target_time.size(), 1);
1708 for (auto& series : time_series_target_time) {
1709 series.second.label = "Target delay";
1710 series.second.style = LINE_DOT_GRAPH;
1711 plot->AppendTimeSeries(std::move(series.second));
1712 }
1713
1714 plot->SetXAxis(0, call_duration_s_, "Time (s)", kLeftMargin, kRightMargin);
1715 plot->SetYAxis(min_y_axis, max_y_axis, "Relative delay (ms)", kBottomMargin,
1716 kTopMargin);
1717 plot->SetTitle("NetEq timing");
1718}
terelius54ce6802016-07-13 06:44:41 -07001719} // namespace plotting
1720} // namespace webrtc